/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
jQuery.noConflict();
var currentIndicator = 0;

jQuery(document).ready(function(){
   
	menu_default();
	
	//Selecciona el lenguaje
	jQuery('#langselect').change(function(){
		
		var langcode = 'esp';
		switch(jQuery(this).val()){
			case '1':langcode = 'esp';break;
			case '2':langcode = 'eng';break;
		}
		
		var here= urlhere.replace(lang,langcode);
		window.location.href = here;
	});
	
	
	//Menu corporativo 
	jQuery('#fringe-submenu').hide();
	jQuery('.corporative').mouseover(function () {
       // jQuery(this).css({ cursor:"wait" });
        if (jQuery('#fringe-submenu').is(":hidden")) {
            jQuery('#fringe-submenu').show();
        } else {
            jQuery('#fringe-submenu').hide();
        }
    });
	
	//Manejo de indicadores
	if(jQuery('.indicators').length > 0){
		jQuery('.indicator').hide();
		//console.log(jQuery('.indicator')[0]);
		jQuery(jQuery('.indicator')[0]).show();
//		alert(jQuery('.indicator')[0]);
		setInterval("indicators()", 4000);
	}
	
	//Slider
	if(jQuery('#slider').length > 0){
		//slider();
		jQuery("#slider").PanoSlider({'width' : '1000', 'height' : '450'})
	}
	
	//Carousel
//	if(jQuery('.jcarousel-skin-tango').length>0){
//	//	carousel();
//	}
	if(jQuery('.carouselite').length>0){
		carousel();
		lightbox();
	}
	
	//Vimeo
	if(jQuery("a[rel=vimeo]").length>0){
		vthumbs();
	}
})

//Indicators
function indicators(){
	if(jQuery('.indicators').length > 0){
		
		jQuery(jQuery('.indicator')[currentIndicator]).hide();
		if(currentIndicator + 1 < jQuery('.indicator').length){
			currentIndicator += 1;
		} else {
			currentIndicator = 0;
		}
		jQuery(jQuery('.indicator')[currentIndicator]).fadeIn('slow');
	}
}

function init(){
	//lightbox();
}

function vthumbs(){
	all=jQuery("a[rel=vimeo]").not(".checked");
	
	for (i = 0; i < all.length; i++) {
		
		id=jQuery(all[i]).attr('code');
		
		jQuery.post(baseurl+'proxies/vimeothumbs?q='+id,function(data){
			
			//jQuery(all[i]).children('img').css("background-image","url("+data[0].thumbnail_small+")");
			jQuery(all[i]).children('img').attr("src",data[0].thumbnail_small);

			jQuery(all[i]).addClass("checked");
			vthumbs();

		});
		break;
	}
}

function slider(){
	jQuery("#slider").SexySlider({
		width     : 1000,
		height    : 450,
		strips    : 10,
		delay     : 4500,
		stripSpeed: 300,
		autopause : false,
		auto      : true,
		navigation: '#navigation',
		control   : '#slider-nav',
		effect    : 'curtain',   // curtain, zipper, wave, fountain, cascade, random
		direction : 'left' // left, right, alternate, random
	});
}

function carousel(){
	//jQuery('.jcarousel-skin-tango').jcarousel();
	jQuery(".carouselite").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		visible:5,
		scroll: 2
    });
}

function vthumbs(){
	all=jQuery("a[rel=vimeo]").not(".checked");
	
	for (i = 0; i < all.length; i++) {
		
		id=jQuery(all[i]).attr('code');
		
		jQuery.post(baseurl+'proxies/vimeothumbs?q='+id,function(data){
			
			//jQuery(all[i]).children('img').css("background-image","url("+data[0].thumbnail_small+")");
			jQuery(all[i]).children('img').attr("src",data[0].thumbnail_small);

			jQuery(all[i]).addClass("checked");
			vthumbs();

		});
		break;
	}
}
