/*
|===================
| Musimax
| author: Roberto Mas + AUI team (Chaines Tele Astral)
| UX and UI issues
|===================
*/

// Execute me first, once the DOM is loaded.
$(document).ready(function(){
	$(function () {

		// Add class on links related to their extensions
		$("a[href$=mp3]").addClass("mp3 music").attr("target","music");
		$("a[href$=pdf]").addClass("pdf").attr("target","pdf");

		// Lightbox set-up
		$('a[rel*=lightbox]').colorbox();
		$('a[rel*=lightboxAlone]').colorbox({iframe:true, innerWidth:500, innerHeight:500});

	});

	/*setup de la liste des albums*/
	$('#album_list li:even .wrapper').attr("style","border-left:none; padding-left:0;");
	$('#album_list li:last').css("border-bottom","none");
	$('#album_list li:last').prev().css("border-bottom","none");


	//If class=inFieldLabel, Move the label within field and hide them onClick (jquery.infieldlabel.min.js)
/*	if ($('form.inFieldLabel').lenght !=0) {
		$('.inFieldLabel label').inFieldLabels();
	};
*/


	//hover des images des articles
	$('.articleImage').each(function () {
			$(this).append('<img class="articleImageHover" src="/img/musimax/article-image-hover.png" />');
			var $img = $('img.articleImageHover', this).css("opacity", "0");
			var $img = $('img.articleImageHover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(450, 0);
			});
		});
	//hover des images des articles
	$('.emissionImage').each(function () {
			$(this).append('<img class="emissionImageHover" src="/img/musimax/emission-image-hover.png" />');
			var $img = $('img.emissionImageHover', this).css("opacity", "0");
			var $img = $('img.emissionImageHover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(450, 0);
			});
		});
	// Fix ticket-113
	// hover des relatedPhotoAlbum
	$('.coupDeCoeurLink').each(function () {
			$(this).append('<img class="carousselImageHover" src="/img/musimax/coupDeCoeurContainer-image-hover.png" />');
			var $img = $('img.carousselImageHover', this).css("opacity", "0");
			var $img = $('img.carousselImageHover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(450, 0);
			});
		});

	//hover des images des caroussel
/*	$('.caroussel_item').each(function () {
			$(this).append('<img class="carousselImageHover" src="img/caroussel-image-hover.png" />');
			var $img = $('img.carousselImageHover', this).css("opacity", "0");
			var $img = $('img.carousselImageHover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(450, 0);
			});
		});
	//hover des images des caroussel
	$('.caroussel_item_other_albums .albumCover').each(function () {
			$(this).append('<img class="carousselImageHover" src="img/caroussel-image-hover.png" />');
			var $img = $('img.carousselImageHover', this).css("opacity", "0");
			var $img = $('img.carousselImageHover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(450, 0);
			});
		});
	// hover des relatedPhotoAlbum
	$('#relatedPhotoAlbum .border_hover').each(function () {
			$(this).append('<img class="carousselImageHover" src="img/relatedPhotoAlbum-hover.png" />');
			var $img = $('img.carousselImageHover', this).css("opacity", "0");
			var $img = $('img.carousselImageHover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(450, 0);
			});
		});

	// hover des relatedPhotoAlbum
	$('#theArtistPhotoGalery .border_hover').each(function () {
			$(this).append('<img class="carousselImageHover" src="img/theArtistPhotoGalery-hover.png" />');
			var $img = $('img.carousselImageHover', this).css("opacity", "0");
			var $img = $('img.carousselImageHover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(450, 0);
			});
		});
*/

	$("a.current").each(function(){
		$(this).parent().css("background-position", "left -37px");
	});



	// Accordeon page de musique
	$('.arrowIcon').click(function() {
		$(this).toggleClass('pointDown');
		$(this).parent().find('.panelContent').removeClass("open");
		$(this).parent().find('.panelContent').slideToggle('fast', function() {
		// Animation complete.
		});
	});
	$('.panel h3 a').click(function() {
		$(this).parent().parent().find('.arrowIcon').toggleClass('pointDown');
		$(this).parent().parent().find('.panelContent').removeClass("open");
		$(this).parent().parent().find('.panelContent').slideToggle('fast', function() {
		// Animation complete.
		});
		return false;
	});
	$('.panelContent').css("display","none");
	$('.panelContent.open').slideToggle('fast', function() {
		// Animation complete.
		});

	// Accordeon de la page horaire
	$('#detailSemaine .panel:even').css("background-color","#dae1e6");
	$('#detailSemaine .panel:odd').css("background-color","#ebebeb");  
	$('.showsByHour:even').css("background-color","#f9f9f9");
	$('.showsByHour:odd').css("background-color","#ebebeb");
	
	$('.showName').click(function() {
		$(this).toggleClass('arrowDown');
		$(this).parent().find('.showsByHour').removeClass("open");
		$(this).parent().parent().find('.showDesciption').slideToggle('fast', function() {
		// Animation complete.
		});
		return false;
	});
	$('.showsByHour .showDesciption').css("display","none");
	$('.showsByHour.open .showDesciption').slideToggle('fast', function() {
		// Animation complete.
		})
	$('.showsByHour.live').find('.showTimeAndName').append('<div class="thisIsLive">En Ondes</div>');


	//ScrollTo page A a Z
	$(".AtoZNav a").click(function(){
		var wichNavElemnet = $(this).attr('title');
		$("html, body").animate({
			scrollTop: $("#"+wichNavElemnet).offset().top
		}, 1000);
		return false;
	});	

	$(".topOfPage").click(function(){
		$("html, body").animate({
			scrollTop: $("#lesTitreAlpha").offset().top
		}, 1000);
		return false;
	});

	//supression des marge des li pour chaque 2ième
	$('.showList').find('li:odd').attr('style', 'margin-right: 0px!important');

	//fade du carousel homepage
	$('#carousel-days').fadeIn();

	// Dynamic Tabs
	$('.tabs_title').click(function(){
		
		$(this).siblings('li').removeClass('current');
		$(this).addClass('current');

		pIndex = $(this).prevAll().length;
		$(this).parent().parent().find('.tabs_panels .tabs_content').removeClass("current").hide();
		$(this).parent().parent().find('.tabs_panels').find('.tabs_content:eq('+pIndex+')').fadeIn().addClass("current");

		//var wichTab = this.href;
		//wichTab = this.href.split("#")[0] + "#" + window.location.hash;
		return false;
	});
/*
	function getUrlHash(){
		$(".tabs_title").each(function(){
			var myHash = window.location.hash;
			if($(this).find('a').attr("href") == myHash){
			
			$('.tabs_title').removeClass('current');
			$(this).addClass('current');
			pIndex = $(this).prevAll().length;
			$('.tabs_content').removeClass("current").hide();
			$('.tabs_panels').find('.tabs_content:eq('+pIndex+')').fadeIn().addClass("current");
			};
		});
	};
	getUrlHash();
*/

	// Dynamic Tabs
	$('.tab_title').click(function(){
		$('.tabs_content').removeClass('current');
		$(this).each(function() {
			var wichTab = this.href;
			//wichTab = this.href.split("#")[0] + "#" + window.location.hash;
			$(this).closest('section').addClass('tabs_content current');
		});
		return false;
	});

/*
	function getUrlHash(){
		$(".tab_title").each(function(){
			var myHash = window.location.hash;
			if($(this).attr("href") == myHash){
				$('nav.tabs .tabs_content').removeClass('current');
				$(this).closest('section').addClass("tabs_content current");
			};
		});
	};
	getUrlHash();

	getTalestContent()

	function getTalestContent(){
		$('.the_tab_content ul').each(function () {
			var tmpHeight = ($(this).height() + $(this).position().top) + (30);
			if (tmpHeight > 200) {
				$(this).parent().parent('.tabs_content').height(tmpHeight);
			};
		});
	};
	$('.tab_title').click(function(){
		getTalestContent()
	});
*/

});




/* 
| ==================================================
| These will start after the DOM [document.ready()] and images are loaded in the page. 
*/
$(window).load(function(){

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

			equalHeight($(".equalCol"));
			//equalHeight($(".sameHeight"));
			equalHeight($(".sameHeightList"));


	//$('.panelContent').css("display","none");
	//$('.panelContent:first').css("display","block");


});

