/*------------------------------------------------------------------
[ Initializing some jQuery functions ]
------------------------------------------------------------------*/

$(document).ready(function(){

		$('a img').hover(	
			function () {
				var currentImg = $(this).attr('src');
				$('img', $(this).attr('src', $(this).attr('rollover')));
				$('img', $(this).attr('rollover', currentImg));
			}, 
			function () {
				var currentImg = $('img', $(this).parent()).attr('src');
				$('img', $(this).attr('src', $(this).attr('rollover')));
				$('img', $(this).attr('rollover', currentImg));
			}	
		)
		
		initRollOvers();
		addCites();
		fixIe6();

		
		// MainNavigation
		// add hover functionality to main navigation
		$('#mainNavigation div.active').attr('class', $('body').attr('class'));
				
/*
		$('#mainNavigation li a').hover(
			function () {		
				var currentImg = $('#mainNavigation ul').attr('class', $('body').attr('class'));
				$('#mainNavigation ul').attr('class', $(this).parent().attr('id'));
			}, 
			function () {
				var currentImg = $('#mainNavigation ul').attr('class', $('body').attr('class'));
				$('#mainNavigation ul').attr('class', currentImg);
			}	
		)
*/				
		// Tickertape
		// tickertape initialize
		$('div#autoscrollNews').autoscroll({animFactor: 20, spacing: 20});
	    $('div#autoscrollLogos').autoscroll({animFactor: 30, spacing: 20});
		 
		 		
		// Add singlepage functonality to links with this class-attr.
		$('a.singlepage').singlepage();
		
	    // Stop productcarrousel if mouseovered on content part.
        $('#outerContentCon').hover(
            function(){
				onRollOverProduct('over'); // argument is not necessarily, maybe for later use
            },
            function(){
                onRollOverProduct('out'); // argument is not necessarily, maybe for later use
            }
        );
		
		
		// Some layout markup for submit-buttons
		$('#submit').wrap('<span class="submitbttn"></span>');
		$('.submit input').hover(function(){
            $(this).addClass('hover');
		}, function () {
		    $(this).removeClass('hover');
		});
		

		// Preload rollover images
		$('img[rollover]').each(function(){
			$.preloadImages($(this).attr('rollover'));
		});

		// Banner rotation
		/*
		if($('div.bbContent div').length > 1) {
			$('div.bbContent').slideshow({
				animSpeed: 500,
				interval: 5000,
				eleType: 'div',
				fadeOver: false
			});
		}
		*/
});

    function fixIe6() {
        if($.browser.msie && $.browser.version <= 6) {
            $('.photoframe img').each ( function (i, el) {
        		$(el).attr('src', $(el).attr('src').replace('.png', '.gif'));
            });
            $('a.play img').each(function(i, el) {
        		$(el).attr('src', $(el).attr('src').replace('.png', '.gif'));
        		$(el).attr('rollover', $(el).attr('rollover').replace('.png', '.gif'));
            });
        	$('#mainTextCon').hover(onRollOverProduct);
        	$('#mainTextCon>*').click(onRollOverProduct);
        	$('input[type=text],textarea')
        	       .css('background-color', '#FFFFFF')
        	       .css('border', '1px solid #9D9D9B');
        	       
		    $('img[src$=.png]').each(function(){
		        $(this).css({
		            filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.src+"')"
		        });
		        this.src = 'images/blank.gif';
		    });
        } 
    }
	
	// Productdetails
	// hide visible content.
	function showPageDetails(){
		$('.visibleContent').fadeOut("fast");
		$('.hiddenContent').fadeIn("slow");						
		return false;
	}
	function hidePageDetails(){
		$('.hiddenContent').fadeOut("fast");
		$('.visibleContent').fadeIn("slow");
		return false;
	}
	
	
	// loads new content on request by productcarrousel
	function loadContentUrl ( contentUrl, callback ) {
	    // q'n'd fix, flash apparently sends the quotes around the argument too.
	    contentUrl = contentUrl.replace( /^'|'$/g, '');
	    
	    $('div#contentLoading').fadeIn('fast');
	    
	    var container = $('#outerContentCon');
	    container.fadeOut("fast", function(){
	       container.load(contentUrl, function(){
	           $(container).fadeIn('fast');
	           flashHeader($('a#flashHeaderDataUrl').attr('href'));
	           if($.isFunction(callback)) {
	               callback();
	           }
			   $('div#contentLoading').fadeOut('fast');
	           $('a.singlepage', $(container)).singlepage();
			   addCites();
			   fixIe6();
			   initRollOvers();
	       });
	    });
	}
		
		
	// SubNavigation
	// resize the element containing the Flash productcarrousel
	$(document).ready(function(){
		$('#subNavigation').height($('#leftCol').height()+50);
	});
	function resizeHeightFlash(height) {
  //	alert('new height:' + height);
	
//		if(height < baseHeight){
//			return false;
//			document.getElementById("subNavigation").style.height = baseHeight+"px";
//		}else {
			document.getElementById("subNavigation").style.height = height+"px";
//		}		
		
		var movie = thisMovie("producten_carrousel");
		movie.style.height = height + "px";
	}
	
	function thisMovie(movieName) {
	    if (navigator.appName.indexOf("Microsoft") != -1) {
	        return window[movieName]
	    }
	    else {
	        return document[movieName]
	    }
	}
	
	// if the visitor hovers over the content, the highlighting in Flash stops.
	function onRollOverProduct() {
		var obj = thisMovie("producten_carrousel");
		if (obj && typeof obj.onRollOverProduct=='function') {
			obj.onRollOverProduct();
		}
	}
	
	// Productcarrousel, keeps loading new content
	function ShowInfoProduct(product_url) {
	   loadContentUrl(product_url);
	}
	
	// Productcarrousel, gets productdetails onclick
	function ShowDetailedInfoProduct(product_url){
	   loadContentUrl(product_url, function(){
		   $('.visibleContent').hide();
	       $('.hiddenContent').show();     
	   });
	}
	
	// to be used when a product has been selected from an external link (ie: not from the flash-navigation)
	// not yet implemented in Flash. AFTIKKEN?
	function selectedProductId(product_id){
		var obj = thisMovie("producten_carrousel");
		if (obj && typeof obj.selectedProductId=='function') {
			obj.selectedProductId(product_id);
		}
	}
	
	function flashHeader ( dataUrl, mode ) {
	    var flashUrl = 'flash/headervisual.swf?v=1.1';
	    var width = '472';
	    var height = '252';
	    
	    if(mode) {
	        flashUrl += '&mode=' + mode;
		    width = '660';
		    height = '260';
	    }
	    $(document).ready(function(){
	        $('#flashHeader').flash({
	                src: flashUrl, 
	                id: 'flashHeader', 
	                width: width,
	                height: height,
	                menu: false, 
	                wmode: 'transparent', 
	                allowScriptAccess:'always',
	                flashvars: {dataUrl: dataUrl}
	            },{ 
	                expressInstall: true,version: '8'
	            }
	        );
	    });
	}
	
	
	// Preload images with rollover-attr.
	$.preloadImages = function() {
	  for(var i = 0; i<arguments.length; i++)  {
	    jQuery("<img>").attr("src", arguments[i]);
	  }
	}
	

	// Add hover functionality to img
	function initRollOvers(){
		// Calls-to-action 		 
		 $('#callstoaction li a').hover(
			function () {		
				var currentImg = $('img', $(this)).attr('src');
				$('img', $(this)).attr('src', $('img', $(this)).attr('rollover'));
				$('img', $(this)).attr('rollover', currentImg);
			}, 
			function () {
				var currentImg = $('img', $(this)).attr('src');
				$('img', $(this)).attr('src', $('img', $(this)).attr('rollover'));
				$('img', $(this)).attr('rollover', currentImg);
			}	
		)
	}
	
	
	function addCites(){
	// add images as cite quotes 
		if ( $(document.body).hasClass('form') ){
			$('#sidebar cite .extended p:first').prepend('<img src="images/icons/ajax-cite-open.gif" width="18" height="17" alt="">');
    		$('#sidebar cite .extended p:last').append('<img src="images/icons/ajax-cite-close.gif" width="17" height="15" border="0" class="citeclose">');
   		} else if ($(document.body).hasClass('projects')|| $(document.body).hasClass('cases')) {
			$('#sidebar cite .extended p:first').prepend('<img src="images/icons/ajax2-cite-open.gif" width="18" height="17" alt="">');
    		$('#sidebar cite .extended p:last').append('<img src="images/icons/ajax2-cite-close.gif" width="17" height="15" border="0" class="citeclose">');
		}else{
			$('#sidebar cite .short p:first').prepend('<img src="images/icons/cite-open.gif" width="13" height="11" alt="">');
			$('#sidebar cite .short p:last').append('<img src="images/icons/cite-close2.gif" width="20" height="11" border="0" class="citeclose">');
			if ( ($('#sidebar cite .extended p:first').length > 0) && ($('#sidebar cite .extended p:last').length > 0) ){
				$('#sidebar cite .extended p:first').prepend('<img src="images/icons/cite-open.gif" width="13" height="11" alt="">');
				$('#sidebar cite .extended p:last').append('<img src="images/icons/cite-close2.gif" width="20" height="11" border="0" class="citeclose">');
			}else{
				$('#sidebar cite .extended').prepend('<p><img src="images/icons/cite-open.gif" width="13" height="11" alt="">');
				$('#sidebar cite .extended').append('<img src="images/icons/cite-close2.gif" width="20" height="11" border="0" class="citeclose"></p>');
			}
		}
	}
	
	
	
