
// constructor function //called from /includes/js/HU-GLOBAL/functions.js
function initSite() {	
    jQuery('.innerlabel', '.search').inputLabel();
    jQuery('.innerlabel', '#research').inputLabel();
	if (jQuery('#hu-showcase').length != 0) { initShowcase(); }
	if (jQuery('#tabs').length != 0) { inittabs(); }
	if (jQuery('#ctrSearchfilter').length != 0) { initSearchFilters(); }
	if (jQuery('#persona').length != 0) { initPersona(); }
	Cufon.replace('.husans');
	slideShow();
}

	//tabs
	function inittabs() {
		jQuery('#tabs').tabs();
		var $tabs = jQuery('#tabs').tabs();
		if (jQuery('.ui-tabs-nav li', '#tabs').length > 1) {
			jQuery('#tabs1').children(":last").prepend(
				jQuery(document.createElement('a'))
					.addClass('morelink')
					.attr('href', 'javascript:void(0)')
					.append(jQuery(document.createTextNode('Uitgebreide informatie')))
					.bind("click", function(){$tabs.tabs('select', 1)})
			);
			jQuery('#tabs2').children(":last").append(
				jQuery(document.createElement('a'))
					.addClass('backbutton')
					.attr('href', 'javascript:void(0)')
					.append(jQuery(document.createTextNode('Terug')))
					.bind("click", function() { $tabs.tabs('select', 0) })
			);
		}
	}

    //init showcase
    function initShowcase() {

    	jQuery('ul.thumbs', '#lead').children().each(
			function() { initthumb(this); }
		);
    	jQuery('ul.thumbs', '#proflisting').children().each(
			function() { initthumb(this); }
		);

    	function initthumb(e) {

			//show popup
			jQuery(e).find("span.video")
				.append(jQuery(document.createElement('img')).attr('src','/includes/img/HU-GLOBAL/playbut.png').addClass('play'))
				.mouseenter(function() {jQuery(this).find(".play").attr('src','/includes/img/HU-GLOBAL/playbutover.png');})
    			.mouseleave(function() {jQuery(this).find(".play").attr('src','/includes/img/HU-GLOBAL/playbut.png');})
				.click(
					function() {

						//check if swfobject embedding has taken place 
						if (jQuery(this).parent().find('object').length == 0) { return false };
						//set the currentflashID to pass to flash video player
						currentflashID = jQuery(this).siblings(':last').find('object').attr('id');

						jQuery(this).siblings(":last").css({
							display: 'block',
							opacity: 0.7
						}).animate({
							width: '380px',
							height: '310px',
							top: '0',
							left: '20px',
							paddingTop: '15px',
							paddingBottom: '15px',
							paddingLeft: '10px',
							paddingRight: '10px',
							opacity: 1
						}, { duration: 400 });
					}
				);

        	//add close button and set behaviour
        	jQuery(e).children(":last").append(
				jQuery(document.createElement('a'))
				.addClass('closebutton')
				.attr('href', 'javascript:void(0)')
				.click(function() {
					jQuery(this).parent().animate({
						width: '0',
						height: '0',
						top: '125px',
						left: '220px',
						marginTop: '15px',
						opacity: '0.1',
						paddingTop: '0',
						paddingBottom: '0',
						paddingLeft: '0',
						paddingRight: '0'
					}, { duration: 600,
						easing: 'easeOutExpo',
						complete: function() { window.document[currentflashID].pauseMovie(); jQuery(this).hide(); }
					});
				})
			);

        } //close init-thumb function
		    
		    
		    
		    
		} //end initShowcase()


		function initSearchFilters()
		{
			target = jQuery('div.filters', '#ctrSearchfilter');
			
			//BEGIN EXPAND
			target.find('h3 a').attr('href', 'javascript:void(0)');
			if (target.children('ul').size() != 0) {
				target.children('ul').each(
				function()
				{
					//Hide Collapsed UL
					if (jQuery(this).attr('class') == "collapsed") {
						if (jQuery(this).find('li.active').size() == 0) {
							jQuery(this).hide().attr('class', 'collapsed');
						}
					}
					else {
						//Hide listitems
						jQuery(this).find('li.hide').hide()

						//Create more button
						if (jQuery(this).find('li.hide').size() != 0) {
							jQuery(this).append(
					    jQuery(document.createElement('li'))
							.append(
								jQuery(document.createElement('a'))
									.attr('href', 'javascript:void(0)')
									.append(
										jQuery(document.createTextNode('meer...'))
									)
									.click(function()
									{

										jQuery(this).parent().siblings(':hidden').slideDown(400).end().hide()

									})
								)
							)
						}
					}
				});

				jQuery('h3', target).click(function()
				{
					var next = jQuery(this).next();
					if (next.is('ul')) {
						jQuery(this).toggleClass('collapsed');
						next.slideToggle();
					}
				});
			}
			//END EXPAND

		}

		//init weblog listing in persona
		function initPersona() {

		    if (jQuery('.flickrthumbs', '#persona').length > 0) {
		        var target = jQuery('.flickrthumbs', '#persona');

		        target.addClass('clearfix');
		        target.children().find('a').attr('href', 'javascript:void(0)');
		        target.children().find('a>img').css({ width: '60px' }).end().find('div').hide();

		        target.children().find('p.comments').after(
				jQuery(document.createElement('a'))
					.addClass('closebutton')
					.attr('href', 'javascript:void(0)')
					.append(jQuery(document.createTextNode('sluiten')))
			);
		        target.children().find('a.closebutton').hide();

		        target.children().toggle(
				function() {

				    jQuery(this).siblings().hide();
				    var all = jQuery(this).parent().find(">li");
				    var position = "0";
				    if (all.index(this) == 1) { position = "72px"; }
				    if (all.index(this) == 2) { position = "144px"; }
				    if (all.index(this) == 3) { position = "216px"; }

				    jQuery(this).css({ // make <li> wider 
				        width: "285px"
				    }).children(':first').css({ // give margin to <a> 
				        marginLeft: position
				    }).animate({ // animate <a> to full width
				        width: "285px",
				        marginLeft: "0px"
				    }).children(':first').animate({ // animate <img> to full width
				        width: "285px"
				    });

				    jQuery(this).children('div.reactions').show();
				    jQuery(this).children('a.closebutton').show();

				},
				function() {

				    var all = jQuery(this).parent().find(">li");
				    var position = "0";
				    if (all.index(this) == 1) { position = "72px"; }
				    if (all.index(this) == 2) { position = "144px"; }
				    if (all.index(this) == 3) { position = "216px"; }

				    jQuery(this).css({ // make <li> original width
				        width: "60px"
				    }).children(':first').animate({ // animate <a> to original width
				        width: "60px",
				        marginLeft: position
				    }).children(':first').animate({	// animate <img> to original width
				        width: "60px"
				    }, "1500",
						function() {
						    jQuery(this).parent().css({ margin: "0" });
						    jQuery(this).parent().parent().siblings().show();
						}
					);

				    jQuery(this).children('div.reactions').hide();
				    jQuery(this).children('a.closebutton').hide();
				}
			);

		    }


		    if (jQuery('.youtubethumbs', '#persona').length > 0) {
		        var target = jQuery('.youtubethumbs', '#persona');

		        target.addClass('clearfix');
		        target.children().find('a').attr('href', 'javascript:void(0)');
		        target.children().find('a>img').css({ width: '60px' }).end().find('div').hide();
		        target.children().find('div.movie').css({ position: 'absolute', zIndex: '1', top: '0', left: '0' }).hide();

		        target.children().find('p.comments').after(
				jQuery(document.createElement('a'))
					.addClass('closebutton')
					.attr('href', 'javascript:void(0)')
					.append(jQuery(document.createTextNode('sluiten')))
			);
		        target.children().find('a.closebutton').hide();


		        target.children().toggle(
				function() {

				    jQuery(this).siblings().hide();

				    var all = jQuery(this).parent().find(">li");
				    var position = "0";
				    if (all.index(this) == 1) { position = "72px" }
				    if (all.index(this) == 2) { position = "144px" }
				    if (all.index(this) == 3) { position = "216px" }


				    jQuery(this).css({ // make <li> wider 
				        width: "285px"
				    }).children(':first').css({ // give margin to <a> 
				        marginLeft: position
				    }).animate({ // animate <a> to full width and fixed height (equal to movie)
				        width: "285px",
				        height: "231px",
				        marginLeft: "0px"
				    }).children(':first').animate({ // animate <img> to full width and fixed height (equal to movie)
				        width: "285px",
				        height: "231px"
				    }, "1500",
				        function() {
				            jQuery(this).parent().parent().children('div.movie').show();
				        }
				    );

				    jQuery(this).children('div.reactions').show();
				    jQuery(this).children('a.closebutton').show();


				},
				function() {

				    var all = jQuery(this).parent().find(">li");
				    var position = "0";
				    if (all.index(this) == 1) { position = "72px"; }
				    if (all.index(this) == 2) { position = "144px"; }
				    if (all.index(this) == 3) { position = "216px"; }


				    jQuery(this).css({ // make <li> original width
				        width: "60px"
				    }).children(':first').animate({ // animate <a> to original width and auto height
				        width: "60px",
				        height: "100%",
				        marginLeft: position
				    }).children(':first').animate({	// animate <img> to original width and auto height
				        width: "60px",
				        height: "100%"
				    }, "1500",
						function() {
						    jQuery(this).parent().css({ margin: "0" });
						    jQuery(this).parent().parent().siblings().show();
						}
					);

				    jQuery(this).children('div.reactions').hide();
				    jQuery(this).children('a.closebutton').hide();
				    jQuery(this).children('div.movie').hide();
				}
			);


		    }

		    if (jQuery('.weblog', '#persona').length > 0) {
		        var target = jQuery(".weblog", '#persona');
		        jQuery("ol", target).slideUp();
		        jQuery("div a", target).attr('href', 'javascript:void(0)')
		        jQuery("div", target).click(function() {
		            jQuery(this).nextAll('ol').toggleClass("expanded");
		            jQuery(this).nextAll('ol').slideToggle();
		        })
		    }
		}

		//slideshow on homepage middle block;

		function slideShow() {

		    if (jQuery("#slideShow").length == 0) {
		        return false;
		    }

		    var canvasWidth = -(jQuery(".slide", "#slideShow").length - 1) * 310;
		    var slideTime = 4;
		    var WaitTime = 15;
		    var timeUnit = 310;
		    var slideTimer = null;
		    var position = 0;
		    
		    jQuery("#ctrMorelink a:not(:first)").hide();

		    jQuery(".slide", "#slideShow").each(function(i) {
		        jQuery(".directaccess ul").append("<li><a href='#'>" + i + "</a></li>");
		    })

		    var tempPos = jQuery(".directaccess li:first", "#slideShow").position().left;

		    jQuery(".currentslide", "#slideShow").css("left", tempPos - 20).css("margin-left", 20);

		    jQuery(".directaccess a").bind("click", function(e) {
		        stop(e);
		        position = jQuery(".directaccess a").index(jQuery(this));

		        jQuery(".canvas", "#slideShow").animate({ "margin-left": -position * 310 }, timeUnit);
		        jQuery(".currentslide", "#slideShow").animate({ "margin-left": (position + 1) * 20 }, timeUnit);

		        updateMorelink(position)
		        clearInterval(slideTimer);
		        slideTimer = setInterval(function() { nextSlide() }, WaitTime * 3 * timeUnit)
		    })

		    jQuery(".canvas", "#slideShow").bind("mouseover", function(e) {
		        clearInterval(slideTimer);
		    })
		    jQuery(".canvas", "#slideShow").bind("mouseout", function(e) {
		        slideTimer = setInterval(function() { nextSlide() }, WaitTime * 3 * timeUnit)
		    })

		    function nextSlide(from) {
		        var endCanvas = jQuery(".canvas", "#slideShow").css("margin-left").split("px")[0] * 1;
		        if (endCanvas <= canvasWidth) {
		            position = 0;
		            jQuery(".canvas", "#slideShow").animate({ "margin-left": 0 }, slideTime * timeUnit)
		            jQuery(".currentslide", "#slideShow").animate({ "margin-left": 20 }, timeUnit);
		        } else {
		            position = position + 1;
		            jQuery(".canvas", "#slideShow").animate({ "margin-left": "-=" + 310 }, slideTime * timeUnit)
		            jQuery(".currentslide", "#slideShow").animate({ "margin-left": "+=" + 20 }, timeUnit);
		        }
		        updateMorelink(position)
		    }

		    function updateMorelink(position) {
		        jQuery("#ctrMorelink a").hide();
		        jQuery("#ctrMorelink a:eq(" + position + ")").show();
		    }

		    slideTimer = setInterval(function() { nextSlide() }, WaitTime * timeUnit)
		}

