/**
 * FileName: site_functions.js
 * Version: 1.0 
 * Creation Date: 2011/06/04 - 13:26
 * Description: This file is used to hold small functions.
 * Author: jcanedo  
 **/
 
// $(document).click(function() {
// 	alert("ok");
// // 	$("a.show_login").css('background','none'); 
// // 	$("div.login_external").hide(); 
// });

$(document).ready(initiating_events);

function initiating_events() {
	
	/** Login Topbar **/
	$("a.show_login").click(function() {
		//check if customer´s session cookie exist
		var _cookie = $.cookie("D-CMS_Active");
		//alert(_cookie);
		if(_cookie == null){			
			$(this).css('background','#242424');
			$("div#login_external").fadeIn('slow');
		}else{
			window.location = '/cgi-bin/panel_customers.pl'
		}
		
	});			 				

	/** ---- Validate Field gCustomSearch ---- **/
	$("input.btn_search[name=sa]").click(function(){	      
		if($("input.txt_search").val() == "") {
			alert("Por favor indica que es lo que estás buscando...");
			$("input.txt_search").focus();
			return false;
		}				
	});	
	
	
	/** ---- Allocate Shadow ---- **/
	var _x = $("td.shadow-sizeL").height();
 	if(_x == '1383') { _x = _x + 57; }
 	if(_x == '1384') { _x = _x + 56; }
  	if(_x == '1023') { _x = _x + 417; }
	$("div.shadow_lateral_l").css('height',_x);
	$("div.shadow_lateral_r").css('height',_x);
	
	
	/** ---- Change Opacity: Story ---- **/
	var _i = $("div.suc_img");
	_i.hover(function () {
		$(this).removeClass("not_active");		                           
		$(this).addClass("active");				
		$("x.active").stop().animate({ opacity: 1 }, 400);
		$("div.not_active").stop().animate({ opacity: 0.4 }, 400);		          
	},function(){                 
		$(this).removeClass("active");
		$(this).addClass("not_active");				
		$("div.not_active").stop().animate({ opacity: 1 }, 400);
	});
	
	
	/** ---- Multimedia Buttons ---- **/
	/** Hidden All Except Content of Images **/	
	$("div#main-container-background div.mobile-public:first").css('display','block');
	
	/** Images ---- **/	
 	$("a#m_images").hover(function () {
 		$(this).css('cursor','pointer');
 		$(this).find("img").attr("src","/images/multimedia/pdr-imagesOvr.jpg");		
 	},function () {
 	 $(this).find("img").attr("src","/images/multimedia/pdr-images.jpg");                   	
 	});				
		
	/** Videos ---- **/
	$("a#m_videos").hover(function () {
		$(this).css('cursor','pointer');
		$(this).find("img").attr("src","/images/multimedia/pdr-videosOvr.jpg");
	},function () {
		$(this).find("img").attr("src","/images/multimedia/pdr-videos.jpg");
	});
	/** Audios ---- **/
	$("a#m_audios").hover(function () {
		$(this).css('cursor','pointer');
		$(this).find("img").attr("src","/images/multimedia/pdr-audiosOvr.jpg");
		$(this).click( function () {
			$("div#main-container-background div.s3").css('display','block');
		});
	},function () {
		$(this).find("img").attr("src","/images/multimedia/pdr-audios.jpg");
	});
	
	
	/** ---- Slider Our Stations ---- **/
	//Show Banner
	$(".main_image .desc").show(); //Show Banner
	$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity
	//Click and Hover events for thumbnail list
	$(".image_thumb ul li:first").addClass('active'); 
	$(".image_thumb ul li").click(function(){ 
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
		var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	
		
		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
			//Animate the Teaser				
			$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
				$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
				$(".main_image img").attr({ src: imgTitle , alt: imgAlt});
			});
		}
		
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});
	//Toggle Teaser
	$("a.collapse").click(function(){
		$(".main_image .block").slideToggle();
		$("a.collapse").toggleClass("show");
	});
	
	/** ---- Our Stations Benefits ---- **/
// 	$("div#international").click(function() {
// 		$("div#international_info").fadeIn("slow");//('display','block');
// 	});		   	
	$("div.image_thumb ul li div").each( function() {		
		
		$(this).click( function () {
		
			$("div.benefits-stations div").css('display','none');
			$("div.benefits-stations div").fadeOut("slow");
			$("div.benefits-stations div").removeAttr("class","list_active");						
			$("div.benefits-stations div").addClass("list_not_active");											
			
// 			alert($(this).attr("id"));
			var gasName = $(this).attr("id");
			gasName = "div.benefits-stations div#" + gasName + "_info";			
// 			alert(gasName);		
			
			$("div.benefits-stations h2").fadeIn("slow");
			$(gasName).removeClass('list_not_active');			
			$(gasName).addClass('list_active')			
			$(gasName).fadeIn("slow");
		}); 
	});
	
	
	/** ---- Weather ---- **/
	//$("select[name=citys] :first").attr("selected", "selected");
	
	$("div.custom_weather div.LMM").css('display','block');

	$("select[name=citys]").change(function(){
			$("div.custom_weather div:visible").each(function() {
				if ( $(this).attr('class') != 'city_weather' ) {
					$(this).css('display', 'none');
					}
				});

			$("div.custom_weather div."+ $(this).val() ).css('display','block');
		});			
	$("select[name=citys_old]").change(function(){
		if($(this).val() == "LMM"){
			$("div.custom_weather div").hide();
		//	$("div.custom_weather div").css('display','none');
			$("div.custom_weather div.LMM").show();
		}
		if($(this).val() == "AHM"){
			$("div.custom_weather div").hide();
		//	$("div.custom_weather div").css('display','none');
			$("div.custom_weather div.AHM").show();
		}
		if($(this).val() == "HTB"){
			$("div.custom_weather div").hide();
		//	$("div.custom_weather div").css('display','none');
			$("div.custom_weather div.HTB").show();
		}
		if($(this).val() == "CBO"){
		$("div.custom_weather div").hide();
		//	$("div.custom_weather div").css('display','none');
			$("div.custom_weather div.CBO").show();
		}				
		if($(this).val() == "CLN"){
			$("div.custom_weather div").hide();
			$("div.custom_weather div.CLN").show();
		///	$("div.custom_weather div").css('display','none');
		//	$("div.custom_weather div.CLN").fadeIn('slow');
		}
		if($(this).val() == "MZT"){
			$("div.custom_weather div").hide();
			//$("div.custom_weather div").css('display','none');
			$("div.custom_weather div.MZT").show();
		}
		if($(this).val() == "HMO"){
			$("div.custom_weather div").hide();
			//$("div.custom_weather div").css('display','none');
			$("div.custom_weather div.HMO").show();
		}
		if($(this).val() == "TIJ"){
			$("div.custom_weather div").hide();
			//$("div.custom_weather div").css('display','none');
			$("div.custom_weather div.TIJ").show();
		}										
      });	
}
