/*
Project: ADN
Date : 	January 2010
Last Update : 06/01/10
Author:	C2iS - AFO
JS for all pages 
*/

$(document).ready(function() {	
	verticalCentering();
	//$(window).bind("resize", verticalCentering);
	
	if($('#menuProduct').length) {$('#menuProduct li:last').addClass('noSeparator');}
			
	if($('#timeLine').length) {	
		equalHeight($(".timeLineText"));		
		timeLine();
	}
	
	if($('#ficheProd').length) {	
		equalHeight($(".tabBloc"));
		tabNav();
		backBtn();
	}
	
	if($('.skinThisForm').length) {
		skinnedSelect();
	}	
	
	if($('.scroll-pane').length) {$('.scroll-pane').jScrollPane({showArrows:true , scrollbarWidth:45 });}	
	
	$('.popinLink').colorbox({opacity:"0.7" , width:"980px" , close:"FERMER" , scrolling:false , scalePhotos:false });

/*functions for IE 6 and IE 7*/
	if ($.browser.msie && $.browser.version <= 7 ) {
		
		$('#nav > li').hover(function() {
			$(this).addClass('sfhover');
		}, function() {
			$(this).removeClass('sfhover');
		});
		
	}	
/*end functions for IE 6 and IE 7*/

/*functions for IE 6*/
	if ($.browser.msie && $.browser.version <= 6 ) {					
		try {
		document.execCommand('BackgroundImageCache', false, true);
		} catch(e) {}	
		
		if($('#nav').length) {
			sizeNav();
		}		
		
		$('#visuProduit').pngFix(); 			
	}	
/*end functions for IE 6*/

});

function verticalCentering() {
	var windowHeight = $(window).height();
	var contentHeight = $('#wrapper').height();	
	var diff = windowHeight - contentHeight;	
	marginToAdd = diff / 2;	
	if(marginToAdd > 15) {
		$('body').css("padding-top",marginToAdd);
	} else {
		$('body').css("padding-top", "0px");
	}	
}

function timeLine() {
	$timeLineLink = $('#timeLine > li a');
	$timeLineText = $('.timeLineText');		
	$timeLineText.hide();
	
	$('#timeLine > li:first a').addClass('lastDate');
	$('#timeLine > li:first').addClass('activeDate');
	var defaultBlocToShow = $('#timeLine > li a.lastDate').attr('href').split('#');
		
	$("#"+defaultBlocToShow[1]).show();
	
	$timeLineLink.click(function() {
		$timeLineText.hide();
		$timeLineLink.parent('li').removeClass('activeDate');
		
		var blocToShow = $(this).attr('href').split('#');
		$("#"+blocToShow[1]).show();
		$(this).parent('li').addClass('activeDate') ;
						
		return false;
	});
	
}

function tabNav() {
	$itemTabNav = $('#ficheProd ul.tabNav li');
	$tabBlocs = $('#tabBlocContainer div.tabBloc');
	
	$itemTabNav.eq(0).addClass('currentTab');
	$tabBlocs.hide();
	$tabBlocs.eq(0).show();
	
	$itemTabNav.children('a').click(function() {
		$tabBlocs.hide();
		var TabToShow = $(this).attr('href').split('#');
		$("#"+TabToShow[1]).show();	
		
		$itemTabNav.removeClass('currentTab');
		$(this).parent('li').addClass('currentTab');
		
		return false;
	})
	
}

function backBtn() {
	$('#btnRetour').hover(function() {
		$(this).stop().animate({left:'304px'})
	}, function() {
		$(this).stop().animate({left:'353px'})
	});
}

function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
        var thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest + 30);
}


function sizeNav() {
	$('#nav > li:gt(0)').each(function() {
		var size = $(this).width();
		//alert(size);
		$(this).find('ul').width(size);
	});
}

function skinnedSelect() {
	$('#contact_objMsg').selectbox({ containerClass: 'selectbox-wrapper contact_objMsg'}); 		
	$('#contact_effectif').selectbox({ containerClass: 'selectbox-wrapper contact_effectif'}); 		
	$('#contact_country').selectbox({ containerClass: 'selectbox-wrapper contact_country'}); 		
	$('#newsletter_country').selectbox({ containerClass: 'selectbox-wrapper newsletter_country'}); 		
}


