// Background Image
var bg_images = new Array();
	bg_images[0] = 'http://www.supracom.nl/cms2/wp-content/themes/supracom/images/mouse_bg.jpg';
	bg_images[1] = 'http://www.supracom.nl/cms2/wp-content/themes/supracom/images/utp_bg.jpg';
	bg_images[2] = 'http://www.supracom.nl/cms2/wp-content/themes/supracom/images/arrow_bg.jpg';

// CASE IMAGES RESIZE
function renderNewDimensions(){
	$("#referenties li img").each(function(index){
		var imgHeight = $(this).height();
		var imgWidth = $(this).width();
		var ratio = imgWidth / imgHeight;	
		var breedte = 270; // BREEDTE is altijd 100%;
		var hoogte = breedte / ratio;
    	$(this).css({width: breedte,height: hoogte});
	});	
};

// INIT THE CAROUSEL
function mycarousel_initCallback(carousel) {
    // EXTERNAL CONTROLS
    $('.jcarousel-control a').bind('click', function() {
        	// SCROLL TO SLIDE
        	carousel.scroll($.jcarousel.intval(jQuery(this).text()));

        	// BLOK VERGROTEN/VERKLEINEN
    		var get_id = $(this).text();
    		var next_height = $(".jcarousel-item-"+get_id).height();
    		$(".jcarousel-list").animate({height: next_height},"fast"); 		
    		
    		// Class toevoegen
    		$(".jcarousel-control a").removeClass("active");
    		$(this).addClass("active");

        return false;
    });
};	

// APPLY RANDOM BG IMAGE
function randomBGimage(id){
	$("#container").css('background-image','url('+bg_images[id]+')');
};

// SUPPORTSOFTWARE OS CHECK
function CheckOS(){
	var strOS = navigator.appVersion;
	if (strOS.toLowerCase().indexOf('win') != -1)
	$("#ss").attr({href: "http://www.supracom.nl/cms2/wp-content/themes/supracom/files/supracom_supportsoftware.exe"});
	else if (strOS.toLowerCase().indexOf('mac') != -1)
	$("#ss").attr({href: "http://www.supracom.nl/cms2/wp-content/themes/supracom/files/supracom_supportsoftware.zip"});
}

// ON DOCUMENT READY
$(document).ready(function() {
                  
        // LOADING CAROUSEL
		$("#referenties").jcarousel({
       		initCallback: mycarousel_initCallback,
        	start: 1,
        	scroll: 1,
        	size: 4,
        	buttonNextHTML: null,
        	buttonPrevHTML: null
    	});
    	
    	// RENDER NEW HEIGHT/WIDTH
    	renderNewDimensions();
    	
    	// DEFAULT HOOGTE BEPALEN
    	var default_height = $(".jcarousel-item-1").height();
    	$(".jcarousel-list").css({height: default_height});   	
    	
		// CLASS FADE_IMG animeren.
		$(".fade_img").css({opacity: 0.5}).mouseover(function(){$(this).animate({opacity: 1.0},"fast")}).mouseout(function(){$(this).animate({opacity: 0.5},"fast")});
				
		//SEARCHFORM
		$("#s").focus(function(){
			if ($(this).attr("value") == "zoeken...")
				{
				$(this).attr({value : ""});
				}
				$(this).addClass("darker");
		});
 		
 		// RANDOM BG IMAGE 
   		var ranNum= Math.floor(Math.random()*bg_images.length);
 		randomBGimage(ranNum);
		
			
		$("#searchsubmit").mouseover(function(){
      	 	$("#searchwrap").addClass("mouseon");
      	 }).mouseout(function(){
      	 	$("#searchwrap").removeClass("mouseon");
      	 });

		// PNG FIX
        $(document).pngFix(); 
		
		// OS CHECK
		CheckOS();	
		
		
		$('.inline.popup').fancybox({
			'frameWidth': 850,
			'frameHeight': 575
		});	
 });
