$(document).ready(function() {

	$("ul.list_artists li:first").addClass("no_top_margin");

	$('.bric_1').innerfade({ speed: 'slow', timeout: 7000, type: 'sequence', containerheight: '90px' });
	$('.bric_2').innerfade({ speed: 'slow', timeout: 8000, type: 'sequence', containerheight: '90px' });
	$('.bric_3').innerfade({ speed: 'slow', timeout: 9000, type: 'sequence', containerheight: '90px' });
	$('.bric_4').innerfade({ speed: 'slow', timeout: 10000, type: 'sequence', containerheight: '90px' });
	$('.bric_5').innerfade({ speed: 'slow', timeout: 11000, type: 'sequence', containerheight: '90px' });
	$('.bric_6').innerfade({ speed: 'slow', timeout: 12000, type: 'sequence', containerheight: '90px' });
	$('.bric_7').innerfade({ speed: 'slow', timeout: 13000, type: 'sequence', containerheight: '90px' });
	$('.bric_8').innerfade({ speed: 'slow', timeout: 14000, type: 'sequence', containerheight: '90px' });
	$('.bric_9').innerfade({ speed: 'slow', timeout: 15000, type: 'sequence', containerheight: '90px' });
	$('.bric_10').innerfade({ speed: 'slow', timeout: 16000, type: 'sequence', containerheight: '90px' });
	$('.bric_11').innerfade({ speed: 'slow', timeout: 17000, type: 'sequence', containerheight: '90px' });
	$('.bric_12').innerfade({ speed: 'slow', timeout: 18000, type: 'sequence', containerheight: '90px' });
	$('.bric_13').innerfade({ speed: 'slow', timeout: 19000, type: 'sequence', containerheight: '90px' });
	$('.bric_14').innerfade({ speed: 'slow', timeout: 6000, type: 'sequence', containerheight: '90px' });
	$('.bric_15').innerfade({ speed: 'slow', timeout: 7500, type: 'sequence', containerheight: '90px' });
	$('.bric_16').innerfade({ speed: 'slow', timeout: 8500, type: 'sequence', containerheight: '90px' });
	$('.bric_17').innerfade({ speed: 'slow', timeout: 12500, type: 'sequence', containerheight: '90px' });
	$('.bric_18').innerfade({ speed: 'slow', timeout: 10500, type: 'sequence', containerheight: '90px' });
	$('.bric_19').innerfade({ speed: 'slow', timeout: 11000, type: 'sequence', containerheight: '90px' });
	$('.bric_20').innerfade({ speed: 'slow', timeout: 11500, type: 'sequence', containerheight: '90px' });
	
	setTimeout(function(){
		$('#wall').fadeIn("slow");
	}, 2000)

	
	$(document).pngFix(); 

		var evenement = url("event");
        $.history.init(function(hash) {
        	if(hash != 'clearbox' && ($('#downer_content').length > 0)){
        		if(hash == '' && evenement == ''){
        			id_event = $("div#focused_id").html();
        			id_artist = $("div#focused_id").html();
        			id_tabs = 0;
        			id_panel = 1;
        			get_artist_from_event(id_event, id_artist, id_tabs, id_panel)
        		}else{
        			hashTokens = hash.split('_');
        			id_artist = hashTokens[1];
        			id_tabs = hashTokens[2];
        			id_panel = hashTokens[3]; 
        			id_event = hashTokens[0];       			
        			if( id_event == ''){
        				id_event = id_artist;
        			}
        			
        			if(hashTokens.length == 4){
        			get_artist_from_event(id_event, id_artist, id_tabs, id_panel)
        			}
        		}
            }   
         });
         
        initMenus();

        $('.history').live('click', function(e) {
                var url = $(this).attr('href');
                url = url.replace(/^.*#/, '');
                $.history.load(url);
                return false;
            });


	$("ul.tabs").tabs("div.panes > div.pane");
	
	$(".archive").corner("cc:#FFF 5px");
	$(".live").corner("cc:#FFF 5px");
	$(".link_podcast").corner("cc:#FFF 5px");
	$(".preconcert").corner("cc:#FFF 5px");
	$(".event_infos").corner("cc:#FFF 5px");
	$(".link_video").corner("cc:#FFF 5px");
	$(".bouton_scene_live").corner("cc:#FFF 5px");
	
	date = new Date()
	day = date.getDate();
	if(day < 10){
		day = "0"+day;
	}
	year = date.getFullYear();
	month = date.getMonth()+1;
	if(month < 10){
		month = "0"+month;
	}
	hour = date.getHours();
	if(hour < 10){
		hour = "0"+hour;
	}
	minutes = date.getMinutes();
	if(minutes < 10){
		minutes = "0"+minutes;
	}
	
	str_date = year.toString()+month.toString()+day.toString();
	str_hour = hour.toString()+minutes.toString();
	
	//str_hour = "2301";
	//str_date = "20100919";
	
	if(str_date <= 20100917){
		$(".tabs li a.current").removeClass("current");
		$(".tabs li a").eq(0).addClass("current");
		$(".panes .pane").each(function(){
			$(this).css("display","none");
		});
		$(".panes .pane").eq(0).css("display","block");
		init_slider_vendredi();
		if(str_hour <= 2230){
			$('.anythingSlider').anythingSlider(1);
		}
		if(str_hour > 2230){
			$('.anythingSlider').anythingSlider(2);
		}
	}
	
	if(str_date == 20100918){
		$(".tabs li a.current").removeClass("current");
		$(".tabs li a").eq(1).addClass("current");
		$(".panes .pane").each(function(){
			$(this).css("display","none");
		});
		$(".panes .pane").eq(1).css("display","block");
		init_slider_samedi();
		if(str_hour <= 1700){
			$('.anythingSlider_samedi').anythingSlider(1);
		}
		if((str_hour >= 1700 && str_hour <= 2300)){
			$('.anythingSlider_samedi').anythingSlider(2);
		}
		if(str_hour >= 2300){
			$('.anythingSlider_samedi').anythingSlider(3);
		}
	}
	
	if(str_date >= 20100919){
		$(".tabs li a.current").removeClass("current");
		$(".tabs li a").eq(2).addClass("current");
		$(".panes .pane").each(function(){
			$(this).css("display","none");
		});
		$(".panes .pane").eq(2).css("display","block");
		init_slider_dimanche();
		if(str_hour <= 1700){
			$('.anythingSlider_dimanche').anythingSlider(1);
		}
		if((str_hour >= 1700 && str_hour <= 2300)){
			$('.anythingSlider_dimanche').anythingSlider(2);
		}
		if(str_hour >= 2300){
			$('.anythingSlider_dimanche').anythingSlider(3);
		}
	}
		
	//id_event = url("event");
	if(evenement != ""){
		id_artist = url("artist");
		tab = url("jour");
		panel = url("heure");
		get_artist_from_event(evenement, id_artist, tab, panel);
	}


	$(".tabs").children("li").eq(0).click(function () { 
    	//$(".pane").eq(1).addClass("initialized");
    	init_slider_vendredi();
    });
    	
	$(".tabs").children("li").eq(1).click(function () {
		init_slider_samedi();
    });
    	
	$(".tabs").children("li").eq(2).click(function () {
		init_slider_dimanche();
	});
	
});

function get_artist_from_event_from_artist_list(id_event, id_artist, id_tabs, id_panel){
	window.location.replace("?page_id=202&event="+id_event+"&artist="+id_artist+"&jour="+id_tabs+"&heure="+id_panel);
}

function get_artist_from_event(id_event, id_artist, id_tabs, id_panel) {
	if(id_tabs == 0){
		$(".tabs li a.current").removeClass("current");
		$(".tabs li a").eq(0).addClass("current");
		$(".panes .pane").each(function(){
			$(this).css("display","none");
		});
		$(".panes .pane").eq(0).css("display","block");
		
		if(id_panel == 1){
			$('.anythingSlider').anythingSlider(1);
		}
		if(id_panel == 2){
			$('.anythingSlider').anythingSlider(2);
		}
	}
	if(id_tabs == 1){
		$(".tabs li a.current").removeClass("current");
		$(".tabs li a").eq(1).addClass("current");
		$(".panes .pane").each(function(){
			$(this).css("display","none");
		});
		$(".panes .pane").eq(1).css("display","block");
		init_slider_samedi();
		if(id_panel == 1){
			$('.anythingSlider_samedi').anythingSlider(1);
		}
		if(id_panel == 2){
			$('.anythingSlider_samedi').anythingSlider(2);
		}
		if(id_panel == 3){
			$('.anythingSlider_samedi').anythingSlider(3);
		}
	}
	if(id_tabs == 2){
		$(".tabs li a.current").removeClass("current");
		$(".tabs li a").eq(2).addClass("current");
		$(".panes .pane").each(function(){
			$(this).css("display","none");
		});
		$(".panes .pane").eq(2).css("display","block");
		init_slider_dimanche();
		if(id_panel == 1){
			$('.anythingSlider_dimanche').anythingSlider(1);
		}
		if(id_panel == 2){
			$('.anythingSlider_dimanche').anythingSlider(2);
		}
		if(id_panel == 3){
			$('.anythingSlider_dimanche').anythingSlider(3);
		}
	}
	$(".pane .wrapper a").each(function(){
		$(this).css("background-color","#777777");
	});
	if($(".artist_"+id_artist).length > 0 ){
		$(".artist_"+id_artist).css("background-color","#D40028");
	}else{
		$(".artist_"+id_event).css("background-color","#D40028");
	}
	
	data_string = "id_post="+id_artist;
	$.ajax({
		type : 'POST',
		url : 'wp-content/themes/labelsuisse/get_artist.php?id_post='+id_artist,
		data : data_string,
		success : function(msg) {
			$("#content_artist").html(msg);
			$(".live").corner("cc:#FFF 5px");
			$(".archive").corner("cc:#FFF 5px");
			$(".preconcert").corner("cc:#FFF 5px");
			$(".event_infos").corner("cc:#FFF 5px");
/* 			$.scrollTo("#downer_content", 1000); */
			initCB();
		}
	}); 
}

function get_artist(id_post) {
	$(".pane .wrapper a").each(function(){
		$(this).css("background-color","#777777");
	});
	$(".artist_"+id_post).css("background-color","#D40028");
	data_string = "id_post="+id_post;
	$.ajax({
		type : 'POST',
		url : 'wp-content/themes/labelsuisse/get_artist.php?id_post='+id_post,
		data : data_string,
		success : function(msg) {
			$("#content_artist").html(msg);
			$(".live").corner("cc:#FFF 5px");
			$(".archive").corner("cc:#FFF 5px");
			$(".preconcert").corner("cc:#FFF 5px");
			$(".event_infos").corner("cc:#FFF 5px");
/* 			$.scrollTo("#downer_content", 1000); */
			initCB();
		}
	});  
}

function init_slider_samedi(){
	classe = $(".pane").eq(1).attr('class');
	if(classe == "pane"){
		$(".pane").eq(1).children('.anythingSlider_samedi').anythingSlider({
			easing: "swing",                // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: false,                 	// This turns off the entire FUNCTIONALY, not just if it starts running or not
	        startStopped: false,          	// If autoPlay is on, this can force it to start stopped
	        delay: 3000,                    	// How long between slide transitions in AutoPlay mode
	        animationTime: 600,          	// How long the slide transition takes
	        hashTags: false,               	// Should links change the hashtag in the URL?
	        buildNavigation: true,       	// If true, builds and list of anchor links to link to each slide
	        pauseOnHover: true,       	// If true, and autoPlay is enabled, the show will pause on hover
	        navigationFormatter: null   	// Details at the top of the file on this use (advanced use)
		});
		
		$("#background_program_samedi_1 a").each(function(){
			height_bloc = $(this).height();
			height_txt = $(this).children("span").height();
			$(this).children("span").css("top",(height_bloc-height_txt)/2);
			$(this).corner("cc:#EFEFEF 5px");
		});
		
		$("#background_program_samedi_2 a").each(function(){
			$(this).corner("cc:#EFEFEF 5px");
			height_bloc = $(this).height();
			height_txt = $(this).children("span").height();
			$(this).children("span").css("top",(height_bloc-height_txt)/2);
		});
		
		$("#background_program_samedi_3 a").each(function(){
			height_bloc = $(this).height();
			height_txt = $(this).children("span").height();
			$(this).children("span").css("top",(height_bloc-height_txt)/2);
			$(this).corner("cc:#EFEFEF 5px");
		});

		$(".anythingSlider_samedi .thumbNav ul li").eq(1).children("a").html("11h-17h");
		$(".anythingSlider_samedi .thumbNav ul li").eq(2).children("a").html("17h-23h");
		$(".anythingSlider_samedi .thumbNav ul li").eq(3).children("a").html("23h-05h");
		$(".pane").eq(1).addClass("initialized");
		$(".thumbNav ul").removeClass("small_ul");
		$(".thumbNav ul").addClass("big_ul");
	}else{
	
	}
}

function init_slider_dimanche(){
	classe = $(".pane").eq(2).attr('class');
	if(classe == "pane"){
		$(".pane").eq(2).children('.anythingSlider_dimanche').anythingSlider({
			easing: "swing",                // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: false,                 	// This turns off the entire FUNCTIONALY, not just if it starts running or not
	        startStopped: false,          	// If autoPlay is on, this can force it to start stopped
	        delay: 3000,                    	// How long between slide transitions in AutoPlay mode
	        animationTime: 600,          	// How long the slide transition takes
	        hashTags: false,               	// Should links change the hashtag in the URL?
	        buildNavigation: true,       	// If true, builds and list of anchor links to link to each slide
	        pauseOnHover: true,       	// If true, and autoPlay is enabled, the show will pause on hover
	        navigationFormatter: null   	// Details at the top of the file on this use (advanced use)
		});
		
		$("#background_program_dimanche_1 a").each(function(){
			height_bloc = $(this).height();
			height_txt = $(this).children("span").height();
			$(this).children("span").css("top",(height_bloc-height_txt)/2);
			$(this).corner("cc:#EFEFEF 5px");
		});
		
		$("#background_program_dimanche_2 a").each(function(){
			$(this).corner("cc:#EFEFEF 5px");
			height_bloc = $(this).height();
			height_txt = $(this).children("span").height();
			$(this).children("span").css("top",(height_bloc-height_txt)/2);
		});
		
		$("#background_program_dimanche_3 a").each(function(){
			height_bloc = $(this).height();
			height_txt = $(this).children("span").height();
			$(this).children("span").css("top",(height_bloc-height_txt)/2);
			$(this).corner("cc:#EFEFEF 5px");
		});
		
		$(".anythingSlider_dimanche .thumbNav ul li").eq(1).children("a").html("11h-17h");
		$(".anythingSlider_dimanche .thumbNav ul li").eq(2).children("a").html("17h-23h");
		$(".anythingSlider_dimanche .thumbNav ul li").eq(3).children("a").html("23h-05h");
		$(".pane").eq(2).addClass("initialized");
		$(".thumbNav ul").removeClass("small_ul");
		$(".thumbNav ul").addClass("big_ul");
	}
}

function init_slider_vendredi(){
	$(".tabs li a.current").removeClass("current");
	$(".tabs li a").eq(0).addClass("current");
	$(".panes .pane").each(function(){
		$(this).css("display","none");
	});
	$(".panes .pane").eq(0).css("display","block");
	classe = $(".pane").eq(0).attr('class');
	if(classe == "pane"){
		$(".pane").eq(0).children('.anythingSlider').anythingSlider({
			easing: "swing",                // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: false,                 	// This turns off the entire FUNCTIONALY, not just if it starts running or not
	        startStopped: false,          	// If autoPlay is on, this can force it to start stopped
	        delay: 3000,                    	// How long between slide transitions in AutoPlay mode
	        animationTime: 600,          	// How long the slide transition takes
	        hashTags: false,               	// Should links change the hashtag in the URL?
	        buildNavigation: true,       	// If true, builds and list of anchor links to link to each slide
	        pauseOnHover: true,       	// If true, and autoPlay is enabled, the show will pause on hover
	        navigationFormatter: null   	// Details at the top of the file on this use (advanced use)
		});
		
		$(".anythingSlider .thumbNav ul li a").eq(1).html("17h-22h30");
		$(".anythingSlider .thumbNav ul li a").eq(2).html("22h30-05h");
		
		$("#background_program_vendredi_1 a").each(function(){
		height_bloc = $(this).height();
		height_txt = $(this).children("span").height();
		$(this).children("span").css("top",(height_bloc-height_txt)/2);
		$(this).corner("cc:#EFEFEF 5px");
	});
	
	$("#background_program_vendredi_2 a").each(function(){
		$(this).corner("cc:#EFEFEF 5px");
		height_bloc = $(this).height();
		height_txt = $(this).children("span").height();
		$(this).children("span").css("top",(height_bloc-height_txt)/2);
		$(".thumbNav ul").removeClass("big_ul");
		$(".thumbNav ul").addClass("small_ul");
	});

		$(".pane").eq(0).addClass("initialized");
		$(".thumbNav ul").removeClass("small_ul");
		$(".thumbNav ul").addClass("big_ul");
	}
}

function url(param) {
	contenu = "";
	var chaine=window.location.search;
	chaine=chaine.substring(1);
	var dz=chaine.indexOf("#",0);
	if(dz!=-1) {
		chaine=chaine.substring(0,dz);
	}
	chaine = chaine+"&";
	if(chaine.indexOf(param,0)!=-1){
		var pos = chaine.indexOf(param,0);
		var pos2 = chaine.indexOf("=",pos);
		var pos3 = chaine.indexOf("&",pos);
		contenu = chaine.substring(pos2+1,pos3);
	}
	return contenu; 
}

function initCB(){
	$('.clearbox').click(function(){
		imageURL = $(this).children('.imageURL').html();
		imageTitle = $(this).children('.imageTitle').html();
		imageTitle = imageTitle.replace("&amp;", "&")
		CB_Open('href='+imageURL+',,type=image,,title='+imageTitle+''); 
	});
	$('.dailymotion').click(function(){
		videoEmbed = $(this).children('.videoEmbed').html();
		videoTitle = $(this).children('.videoTitle').html();
		videoTitle = videoTitle.replace("&amp;", "&")
		CB_Open('href='+videoEmbed+',,html='+videoEmbed+',,width=562,,height=316,,type=inner,,title='+videoTitle+''); 
	});
	
	$('.spot_video').click(function(){
		videoEmbed = $(this).children('.videoEmbed').html();
		videoTitle = $(this).children('.videoTitle').html();
		videoTitle = videoTitle.replace("&amp;", "&")
		CB_Open('href='+videoEmbed+',,html='+videoEmbed+',,width=648,,height=392,,type=inner,,title='+videoTitle+''); 
	});	
	
	$('.spot_video_bric').click(function(){
		videoEmbed = $(this).children('.videoEmbed').html();
		videoTitle = $(this).children('.videoTitle').html();
		videoTitle = videoTitle.replace("&amp;", "&")
		CB_Open('href='+videoEmbed+',,html='+videoEmbed+',,width=648,,height=392,,type=inner,,title='+videoTitle+''); 
	});	
	
	
	$('.spot_video_2').click(function(){
		videoEmbed = $(this).children('.videoEmbed').html();
		videoTitle = $(this).children('.videoTitle').html();
		videoTitle = videoTitle.replace("&amp;", "&")
		CB_Open('href='+videoEmbed+',,html='+videoEmbed+',,width=648,,height=392,,type=inner,,title='+videoTitle+''); 
	});	
	
	$('.mx3_video').click(function(){
		videoEmbed = $(this).children('.videoEmbed').html();
		videoTitle = $(this).children('.videoTitle').html();
		videoTitle = videoTitle.replace("&amp;", "&")
		CB_Open('href='+videoEmbed+',,html='+videoEmbed+',,width=505,,height=403,,type=inner,,title='+videoTitle+''); 
	});	
}


