$(document).ready(function(){

	/*************************************************
	 - Acordion -
	*************************************************/
	$("#accordion").accordion();
	
	/*************************************************
	 - Rotativo -
	*************************************************/
	$('#rotativo').cycle({ 
    fx:             'fade', // name of transition effect (or comma separated names, ex: fade,scrollUp,shuffle) 
    timeout:         6000,  // milliseconds between slide transitions (0 to disable auto advance) 
    timeoutFn:       null,  // callback for determining per-slide timeout value:  function(currSlideElement, nextSlideElement, options, forwardFlag) 
    continuous:      0,     // true to start next transition immediately after current one completes 
    speed:           500,  // speed of the transition (any valid fx speed value) 
    speedIn:         null,  // speed of the 'in' transition 
    speedOut:        null,  // speed of the 'out' transition 
    next:            null,  // selector for element to use as click trigger for next slide 
    prev:            null,  // selector for element to use as click trigger for previous slide 
    prevNextClick:   null,  // callback fn for prev/next clicks:    function(isNext, zeroBasedSlideIndex, slideElement) 
    prevNextEvent:  'click.cycle',// event which drives the manual transition to the previous or next slide 
    pager:           null,  // selector for element to use as pager container 
    pagerClick:      null,  // callback fn for pager clicks:    function(zeroBasedSlideIndex, slideElement) 
    pagerEvent:     'click.cycle', // name of event which drives the pager navigation 
    allowPagerClickBubble: false,  // allows or prevents click event on pager anchors from bubbling 
    pagerAnchorBuilder: null, // callback fn for building anchor links:  function(index, DOMelement) 
    before:          null,  // transition callback (scope set to element to be shown):     function(currSlideElement, nextSlideElement, options, forwardFlag) 
    after:           onAfter,  // transition callback (scope set to element that was shown):  function(currSlideElement, nextSlideElement, options, forwardFlag) 
    end:             null,  // callback invoked when the slideshow terminates (use with autostop or nowrap options): function(options) 
    easing:          null,  // easing method for both in and out transitions 
    easeIn:          null,  // easing for "in" transition 
    easeOut:         null,  // easing for "out" transition 
    shuffle:         null,  // coords for shuffle animation, ex: { top:15, left: 200 } 
    animIn:          null,  // properties that define how the slide animates in 
    animOut:         null,  // properties that define how the slide animates out 
    cssBefore:       null,  // properties that define the initial state of the slide before transitioning in 
    cssAfter:        null,  // properties that defined the state of the slide after transitioning out 
    fxFn:            null,  // function used to control the transition: function(currSlideElement, nextSlideElement, options, afterCalback, forwardFlag) 
    height:         'auto', // container height 
    startingSlide:   0,     // zero-based index of the first slide to be displayed 
    sync:            1,     // true if in/out transitions should occur simultaneously 
    random:          0,     // true for random, false for sequence (not applicable to shuffle fx) 
    fit:             0,     // force slides to fit container 
    containerResize: 1,     // resize container to fit largest slide 
    pause:           0,     // true to enable "pause on hover" 
    pauseOnPagerHover: 0,   // true to pause when hovering over pager link 
    autostop:        0,     // true to end slideshow after X transitions (where X == slide count) 
    autostopCount:   0,     // number of transitions (optionally used with autostop to define X) 
    delay:           0,     // additional delay (in ms) for first transition (hint: can be negative) 
    slideExpr:       null,  // expression for selecting slides (if something other than all children is required) 
    cleartype:       !$.support.opacity,  // true if clearType corrections should be applied (for IE) 
    cleartypeNoBg:   false, // set to true to disable extra cleartype fixing (leave false to force background color setting on slides) 
    nowrap:          0,     // true to prevent slideshow from wrapping 
    fastOnEvent:     0,     // force fast transitions when triggered manually (via pager or prev/next); value == time in ms 
    randomizeEffects:1,     // valid when multiple effects are used; true to make the effect sequence random 
    rev:             0,     // causes animations to transition in reverse 
    manualTrump:     true,  // causes manual transition to stop an active transition instead of being ignored 
    requeueOnImageNotLoaded: true, // requeue the slideshow if any image slides are not yet loaded 
    requeueTimeout:  250,   // ms delay for requeue 
    activePagerClass: 'activeSlide', // class name used for the active pager link 
    updateActivePagerLink: null // callback fn invoked to update the active pager link (adds/removes activePagerClass style) 
});
	
	function onAfter() { 
		$('div.rotative-item-title').html($(this).attr("title"));
		$('div.rotative-item-review p').html($(this).attr("rel"));
		$('div.rotative-item-review a').attr("target", $(this).attr("target"));
		$('div.rotative-item-review a').attr("href", $(this).attr("href"));
	} 
	
	/*************************************************
	 Personaliza fondo
	*************************************************/


    $("li.item1").click( function(){ 
		$("#main").removeClass('bg2 , bg3 , bg4 , bg5').addClass("bg1");
		$("body").css("color", "#FFF");
		$("a").css("color", "#FFF");
		$("#logo h1").removeClass("black").addClass("white");

	});

	$("li.item2").click( function(){ 
		$("#main").removeClass("bg1 , bg3 , bg4 , bg5").addClass("bg2");
		$("body").css("color", "#000");
		$("a").css("color", "#000");
		$("#rotativo h4").css("color", "#0F0");
		$("#logo h1").removeClass("black").addClass("black");

	});

	$("li.item3").click( function(){ 
		$("#main").removeClass("bg1 , bg2 , bg4 , bg5").addClass("bg3");
		$("body").css("color", "#FFF");
		$("a").css("color", "#FFF");
		$("#logo h1").removeClass("black").addClass("white");

	}); 
	
	$("li.item4").click( function(){ 
		$("#main").removeClass("bg1 , bg2 , bg3 , bg5").addClass("bg4");
		$("body").css("color", "#000");
		$("a").css("color", "#000");
		$("#logo h1").removeClass("white").addClass("black");
	}); 
	
	$("li.item5").click( function(){ 
		$("#main").removeClass("bg1 , bg2 , bg3 , bg4").addClass("bg5");
		$("body").css("color", "#555");
		$("#logo h1").removeClass("black").addClass("white");
	}); 


	/*************************************************
		Lo mas visto Tabs
	*************************************************/
	$(".navigation li").click(function(){

		$(".navigation li").removeClass("selected");
		$(this).addClass("selected");
	
	});
	
	/*************************************************
	 Sliding file upload
	*************************************************/
	
	$('.haccordion ul li div').click(function(){
		$("#fileUpload").animate({'height':'230px'},500);
		$('#fileUpload strong').html($(this).attr('id'));
	});
	
	/**
	 * Función para hacer el switch del idioma
	 */
	$("#chooseLanguage ul li a").click(function(){
	
		var newLanguage = $(this).attr("rel");
		window.location = $('base').attr('href')+'backends/switch_language.php?newLanguage='+newLanguage;
		return false;
	
	});
		
	/*********************************************
	 - Cargar los videos del Home
	*********************************************/
	$('.loMasVisto ul li a img').click(function(){
		var vVideoFlvUrl = $(this).attr("rel");
		var vVideoType = $(this).attr("rel2");
		var vVideoDescription = $(this).attr("rel3");
		var sURLVideo = '';
		if(vVideoType == 'youtube')
		{
			$("#description_video").html('<p>'+vVideoDescription+'</p>');
			sURLVideo = '<object width="320" height="240"><param name="movie" value="http://www.youtube.com/v/'+vVideoFlvUrl+'&autoplay=1&hl=es_MX&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+vVideoFlvUrl+'&autoplay=1&hl=es_MX&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="240"></embed></object>';
			$("#player-holder").html(sURLVideo);
		}
		else
		{
			sURLVideo = 'videos/'+vVideoFlvUrl;
			$("#description_video").html('<p>'+vVideoDescription+'</p>');
			$("#player-holder").html('');
			$('#player-holder').flash(
			{ 
					swf: 'swf/player.swf?flv='+sURLVideo,
					width: 320,
					height: 240 
			});
		}
	});
	/*********************************************
	 - Cargar los videos del Video Internal
	*********************************************/
	$('.itemOthers div ul li a img').click(function(){
		var vVideoFlvUrl = $(this).attr("rel");
		var vVideoType = $(this).attr("rel2");
		var vVideoDescription = $(this).attr("rel3");
		var vVideoName = $(this).attr("rel4");
		var sURLVideo = '';
		if(vVideoType == 'youtube')
		{
			//alert('<h4>'+vVideoName+'</h4><p>'+vVideoDescription+'</p>');
			$("#description_video_info").html('<h4>'+vVideoName+'</h4><p>'+vVideoDescription+'</p>');
			sURLVideo = '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/'+vVideoFlvUrl+'&autoplay=1&hl=es_MX&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+vVideoFlvUrl+'&autoplay=1&hl=es_MX&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>';
			$("#player").html(sURLVideo);
		}
		else
		{
			sURLVideo = 'videos/'+vVideoFlvUrl;
			$("#description_video_info").html('<h4>'+vVideoName+'</h4><p>'+vVideoDescription+'</p>');
			$("#player").html('');
			$('#player').flash(
			{ 
					swf: 'swf/player.swf?flv='+sURLVideo,
					width: 640,
					height: 385 
			});
		}
	});
	
	/**
	 * Función para cambiar el tamaño al texto
	 */
	$('p.changer').click(function(){
	
		var ourText = $('#articleHolder');
		var currFontSize = ourText.css('fontSize');
		var originalFontSize = ourText.css('fontSize');
		var finalNum = parseFloat(currFontSize, 10);
		var stringEnding = currFontSize.slice(-2);
		
		if(this.id == 'large') {
			
			finalNum *= 1.2;
			
		}
		
		else if (this.id == 'small'){
			
			finalNum /=1.2;
			
		}
	
		ourText.css('fontSize', finalNum + stringEnding);
	
	});
		
	$('p.resetter').click(function(){
	
		var ourText = $('#articleHolder');
		var originalFontSize = $(this).prev().css('fontSize');
		
		ourText.css('fontSize', originalFontSize);
	
	});
	
});

/**
 * Función para mostrar los errores de un formulario
 * @param string msg mensaje de error
 */
function displayError(msg){

	$("#display_errors").show();
	$("#display_errors").html(msg);

}

/**
 * Función para mostrar el mensaje de exito de un formulario
 * @param string msg mensaje de error
 * @param string formID id con el formulario que se va a ocultar
 */
function displaySuccess(msg){

	$("form.uploadFormLayout").hide();
	$("#display_errors").hide();
	$("#form_msgs").show();
	$("#form_msgs").children().html(msg);

}

/**
 * Función para actualizar el captcha
 */
function refreshCaptcha(){

	var imageURL = 'classes/securimage/securimage_show.php?sid='+Math.random();
	
	$("#captcha_image").attr("src", imageURL);

}