/*JS*/

$(document).ready(function() {	
	if($('#nav').length) {
		nav();
	}
	
	if($('#home').length) {
//		switcherNewsHome();
	}
	
	if($('#logBox').length) {
		skinnedSelect();
	}
		
	if($('#ficheEntreprise_sidebar').length) {	
		initCarouselEntreprise();
//		initMapEntreprise();
	}
	
	if($('#tabAccount').length) {
		switcherAccount();
	}
	
	if($('#tabAnnuaire').length) {
		switcherAnnuaire();
	}
	
	if($('#actus').length) {
		$('#actus > li:last').addClass('last');
	}
	
	if($('.blocSlider').length) {
		blocSlider();
	}
	
	var myUrl = document.location.toString();
	if (myUrl.match('#')) {
		var myAnchor = myUrl.split('#')[1];
		if (myAnchor ==	'formulaire_lettres'){
			$.fn.colorbox({opacity:"0.7" , width:"615px" , close:"FERMER" , scrolling:false , scalePhotos:false ,inline:true, href:"#formulaire_lettres"});
		}
	}
	if (myUrl.match('message=validation_abonnements_succes') 
		|| myUrl.match('message=validation_changement_format_succes')
			|| myUrl.match('message=validation_desabonnements_succes')) {
		myAnchor ==	'formulaire_lettres'
		$.fn.colorbox({opacity:"0.7" , width:"615px" , close:"FERMER" , scrolling:false , scalePhotos:false ,inline:true, href:"#formulaire_lettres"});
	}
	
	
	$('.popinLink').click(function() {
		var popinToShow = $(this).attr('href');			
		$.fn.colorbox({opacity:"0.7" , width:"615px" , close:"FERMER" , scrolling:false , scalePhotos:false ,inline:true, href:popinToShow});
		return false;
	});
	
	$('.popinLinkNoWidth').click(function() {
		var popinToShow = $(this).attr('href');			
		$.fn.colorbox({opacity:"0.7" , close:"FERMER" , scrolling:false , scalePhotos:false ,inline:true, href:popinToShow});
		return false;
	});
		
	
/*only functions for IE 6*/
	if ($.browser.msie && $.browser.version <= 6 ) {
		try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {} //caching CSS images	
		 $('#searchBox').pngFix(); 		 
	}		
/*end IE6*/		
});

function nav() {
	
	$('#nav li a.active').next('ul').show();
	
	$('#nav > ul > li > a').click(function() {
		if($(this).next('ul').length) {
			$('#nav > ul > li > ul').slideUp();
			$(this).next('ul:hidden').slideDown();
			return false;
		}
		else {
			return true;
		}
	});
	
	$('#nav > ul > li > ul > li > a').click(function() {
		if($(this).next('ul').length && $(this).attr('href') == "#") {
			$('#nav > ul > li > ul > li > ul').slideUp();
			$(this).next('ul:hidden').slideDown();
			return false;
		}
		else {
			return true;
		}
	});
}

function initCarouselEntreprise() {
	 $("#carouselPhoto .innerCarousel").jCarouselLite({
		visible: 1 ,	
		auto: 2000,
		speed: 1000	
    });
} 

function switcherAccount() {
	$tabBloc = $('.tabBloc');
	$triggerTabBloc = $('#tabAccount > li > a');
	
	
	var myUrl = document.location.toString();
	if (myUrl.match('#')) {
		var myAnchor = myUrl.split('#')[1];
		if (myAnchor == 'fiche'){
			$tabBloc.eq(1).show();
			$triggerTabBloc.eq(1).addClass('active');
		}
		else {
			$tabBloc.eq(0).show();
			$triggerTabBloc.eq(0).addClass('active');
		}
	}
	else {
		$tabBloc.eq(0).show();
		$triggerTabBloc.eq(0).addClass('active');
	}
	
	$('#privateDocs > li:last').addClass('last');

	$triggerTabBloc.click(function() {
		$('#msg').hide();
		var blocToShow = $(this).attr('href').split('#');
		$tabBloc.hide();
		$triggerTabBloc.removeClass('active');
		$("#"+blocToShow[1]).show();
		$(this).addClass('active');
		return false;
	});
}

function blocSlider() {
	$('.blocSlider > dt').click(function() {
		$('.blocSlider > dd').slideUp();
		$(this).parent('dl').children('dt').removeClass('active');		
		$(this).next('dd:hidden').slideDown('normal',function() {
			$(this).prev('dt').addClass('active');
		});		
	});
	
	$('.blocSlider > dd dt').click(function() {
		$('.blocSlider > dd dd').slideUp();
		$(this).parent('dl').children('dt').removeClass('active');
		$(this).next('dd:hidden').slideDown('normal', function(){
			$(this).prev('dt').addClass('active');
		});
	});
}

function switcherNewsHome() {
	$triggerNewsHome = $('#newsHome ul > li > a');
	$tabBlocHome = $('#newsHome .tabBloc');
	$tabBlocHome.eq(0).show();
	$triggerNewsHome.eq(0).addClass('active');	
	
	$('#newsHome ul > li > a').click(function() {
		var tabToShow = $(this).attr('href').split('#');
		$tabBlocHome.hide();
		$triggerNewsHome.removeClass('active');	
		$("#"+tabToShow[1]).show();
		$(this).addClass('active');
		return false;
	});
}

function skinnedSelect() {
	$('#yourActivity').sSelect();
}

function imprime() {
	if (typeof(window.print) != 'undefined'){
		window.print();
	}
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};



