////////////////////////////////////////////////////////  
//Desarrollo:    GameMaster
//Proyect0:      2010 Lanzamiento
//Autor:	 Edgar Alarcon http://reda.gamemaster.com.mx
//Fecha:         10.07.10


//BORRA LOS VALORES DE LOS CAMPOS DE ENTRADA
////////////////////////////////////////////////////////
$.fn.cleardefault = function() {
	
	return this.focus(function() {
		
		if ( this.value == this.defaultValue ) {
		this.value = "";
		
		//console.log("clear my defaults dammit");
		
		}
		
	}).blur(function() {
			
		if ( !this.value.length ) {
		this.value = this.defaultValue;
		
		}
		
	});
};

////////////////////////////////////////////////////////
//IMAGEN BTTN FADE & BORDES REDONDEADOS
////////////////////////////////////////////////////////
this.bttns = function(){	
	
	$(".bttn-image").hover(function(e){
		
		$(this).css("opacity", .6);	
    },
	
	function(){
		
		$(this).css("opacity", 1);
    });
    
    $(".bttn-round").append("<div class='bttn-round-image left'></div><div class='bttn-round-image right'></div>");	
				
};
////////////////////////////////////////////////////////
//INICIO NAV
////////////////////////////////////////////////////////
this.homenav = function(){

	$("#section-nav li").hover(function(e){
	
		var $this = $(this); //li
		//console.log('hover', $this, $this.find("> ul li"));
		if ($this.find("> ul li").length){
			//console.log('found ', $this.find("> ul li").length, $this.find("> ul li").get());
			$this.addClass("active").children(".sub-nav").show();
			$("ul.sub-nav li").removeClass("active");
		
		}
	},
	
	function(){
		
		$(this).removeClass("active").children(".sub-nav").hide();
	
	});
	
	$("#section-nav .sub-nav li").hover(function(e){
	
		var newposition = "-" + $(this).children(".tertiary-nav").width();
	
		$(this).addClass("active").children(".tertiary-nav").css("right", newposition + "px").show();
		$("ul.tertiary li").removeClass("active");
	},
	
	function(){
		
		$(this).removeClass("active").children(".tertiary-nav").hide();
	
	});
	
    if ($("ul.sub-nav").length > 0) {
        $("ul.sub-nav").corner("br");
    }
	
    if ($("ul.sub-nav li:last-child").length > 0) {
        $("ul.sub-nav li:last-child").corner("br");
    }
    
    if ($("ul.tertiary-nav").length > 0) {
        $("ul.tertiary-nav").corner("br");
    }
	
	//$("ul.sub-nav").corner("br");
	
	//$("ul.sub-nav li.last").corner("br");
	
	//$("ul.tertiary-nav").corner("br");
	
};
	

////////////////////////////////////////////////////////
//NAV 2
////////////////////////////////////////////////////////
this.athletenav = function(){

	$(".athlete-nav li.athlete-letters").hover(function(e){
	
		$(this).addClass("active").children("ul").show();
		$(".athlete-nav ul").after("<img class='arrow' src='/images/arrow_athlete-nav.gif' alt='arrow_athlete-nav' width='19' height='10' />");
		
	},
	
	function(){
		
		$(this).removeClass("active").children("ul").hide();
		$(".arrow").remove();
	
	});
	
    if ($(".athlete-nav ul").length > 0) {
        $(".athlete-nav ul").corner("br");
    }
		
};

////////////////////////////////////////////////////////
//TABS
////////////////////////////////////////////////////////
this.athletetabs = function() {

	//parametros de tab 
	var tabOptsAth = {

		fx: {
			opacity: "toggle",
			duration: "fast" 
		}, 
	  
		selected: 0

	};

	//tab de cta
    if ($("#athlete-tabs").length > 0) {
        $("#athlete-tabs").tabs(tabOptsAth);
    }

};

////////////////////////////////////////////////////////
//INICIA EL SISTEMA
////////////////////////////////////////////////////////
this.rating = function() {
	$(".rating-stars .none").click(function(e){
        if($(this).attr('rel') == 'noclick') { return; }
		var postdata = $(this).attr("name");
		$(this).prevAll().andSelf().addClass("rated");
		//remove click event, move to ajax success handler
		$(this).siblings().andSelf().removeClass("none").unbind("click");
	});
	$(".rating-stars .none").hover(function(e){
        if($(this).attr('rel') == 'noclick') { return; }
		$(this).prevAll(".none").andSelf().addClass("over");
	}, function(e){
        if($(this).attr('rel') == 'noclick') { return; }
		$(this).prevAll(".none").andSelf().removeClass("over");
	});
};

////////////////////////////////////////////////////////
//TEXTO DE LA IMAGEN PRINCIPAL
////////////////////////////////////////////////////////
$.fn.resize = function() {
	
	if ($("#leading-image").hasClass("left-align") || $("#leading-image").hasClass("right-align")) {
	
		var imageHeight = $("#leading-image img").height();
		//removiendo padding
		var adjustHeight = imageHeight - 20;
		
		$("#leading-image span").height(adjustHeight);
		
	} 
		
};

////////////////////////////////////////////////////////
//INICIO CTA
////////////////////////////////////////////////////////
this.ctahome = function() {

	if ($('#cta-home').length == 0) {
	    return;
	}

	//parametros del tab
	var tabOpts = {

		fx: {
			opacity: "toggle",
			duration: "fast" 
		}, 
	  
		selected: 0

	};

	//tab de cta
	$("#cta-home").tabs(tabOpts).tabs("rotate", 5000);
;
	
	$(".cta-home-panel span").append("<a class='nav-up'><img src='/images/bttn_cta-home-up.png' alt='Up' width='17' height='9' /></a><a class='nav-down'><img src='/images/bttn_cta-home-down.png' alt='Down' width='17' height='9' /></a>");
		
	//escoder thumbs
	//$(".cta-home-panel span").css("bottom", "129px");
	//$("#cta-nav").css("bottom", "0");
	
	//slide thumbs hacia arriba
	$("a.nav-up").click(function(e){
	
		$(".cta-home-panel span").animate({
		
			bottom: "129px"}, 300);
			
		$("#cta-nav").animate({
		
			bottom: "0"}, 300);
			
	});
	
	
	//slide thumbs hacia abajo
	$("a.nav-down").click(function(e){
	
		$(".cta-home-panel span").animate({
		
			bottom: "0"}, 300);
			
		$("#cta-nav").animate({
		
			bottom: "-130px"}, 300);
			
	});

	
};

function display_events()
{
	if( $('#convertible_event_nav').length != 0 )
	{
			if( $("#convertible_event_nav").css("display") == 'none' )
			{
				$("#convertible_event_nav").css("display","block");
			}
			else
			{
				$("#convertible_event_nav").css("display","none");
			}
	}
	else
	{
		return false;
	}
}

////////////////////////////////////////////////////////
//DOCUMENTO LISTO
////////////////////////////////////////////////////////
$(document).ready(function(){

//forzando zend_forms a obedecer mis estilos designados 
	$(".zend_form input[type='submit']").addClass("standard-form-submit");	
        $("input.clear-default").cleardefault();   
        $("#leading-image").resize();   
          bttns();   
          rating();   
          ctahome();   
          homenav();   
          athletenav();	
          athletetabs();   
	
	//corrige errores de la css en el navegador
	if ($.browser.msie && $.browser.version.substr(0,1)<=7) {
    
  		$('<span class="ie-rule" />').insertAfter('dl dd');
  		
  		$('form input:radio, form input:checkbox').addClass('ie-radio-check');
  	  
  	}
  	
  	//error en el navegador
	if ($.browser.msie) {
	      		
  		$('form input:checkbox, form input:radio').addClass('ie-radio-check');
  	  
  	}

	//errores y mensajes de los sucesos
	
	if($("#flashed:has(p)")){
		
			setTimeout(function(){
    		
    			$("#flashed p").fadeOut('fast');
			
			}, 1000);
		
		}
		
		
	if( $(".content p:has(img)") && $(".content p:has(text)")) {
	
		$(".content p img").each(function() {
        
        	$(this).parent().addClass("show-inline");
        	 
		});    			
	}


	$('#events_link').click(function() 
	{
		display_events();
	}); 	
	
});

