// JavaScript Document

$(document).ready(function() {				   
	/* Homepage Slider */	
	$('#coda-slider-1').codaSlider({
		autoSlide: true, 
		autoSlideInterval: 6000,
		slideEaseDuration: 1600, 
		slideEaseFunction: 'easeInOutExpo', 
		dynamicTabsAlign: 'right',
		dynamicArrows: false, 
		crossLinking: false
	});	
});

/*var trade8 = { src: 'js/sifr3/00trade8.swf' };
			
sIFR.activate(trade8);
			
sIFR.replace(trade8, {
	selector: '.counter_label',
	css: [ '.sIFR-root {font-size:14px;color:#4d4d4d;font-weight:bold;}' ],
	wmode: 'transparent'
});
sIFR.replace(trade8, {
	selector: '.blue',
	css: [ '.sIFR-root {font-size:14px;color:#4d4d4d;font-weight:bold;}' ],
	wmode: 'transparent'
});*/

$(document).ready(function() {
	/*$(document).bind("contextmenu",function(e){
		alert("Propiedad de CATCHERMEDICO");
		return false;
	});*/
		
	/* Add play buttons on class .videoThumb */	
	$('.videoThumb').prepend('<span></span>');
	
	/* Remove the scrolbars from textarea in Opera  */	
	$.each($.browser, function(i) {
		if($.browser.opera) $("textarea").css("overflow","hidden");
	});
		
	/* Start Portofolio Carousel */
	$("#portofolioSlider .carousel").jcarousel({
		scroll: 5,
		animation: 1500,
		easing: 'easeOutExpo',
		initCallback:  portofolioCarouselInit,
		buttonNextCallback: portofolioCarouselNext,
		buttonPrevCallback: portofolioCarouselPrev,
		itemLoadCallback: {onAfterAnimation: portofolioCarouselCounter}
	});
});

/* Portofolio Carousel Callback Functions */
var itemP, itemN;
function portofolioCarouselInit(carousel) {
	$('#portofolioSlider .jcarousel-next').bind('click', function() {
		carousel.next();
		return false;
	});	
	$('#portofolioSlider .jcarousel-prev').bind('click', function() {
		carousel.prev();
		return false;
	});
};
function portofolioCarouselNext(carousel, button, enabled) {
	enabled ? $('#portofolioSlider .jcarousel-next').removeClass("disabled") : $('#portofolioSlider .jcarousel-next').addClass("disabled");
};
function portofolioCarouselPrev(carousel, button, enabled) {
	enabled ? $('#portofolioSlider .jcarousel-prev').removeClass("disabled") : $('#portofolioSlider .jcarousel-prev').addClass("disabled");
}; 
function portofolioCarouselCounter(carousel, state) {
	if(state == "init") {
			itemN = $("#portofolioSlider .carousel ul li").size();
			itemN < 4 ? itemP = itemN : itemP = 4;
			$("#portofolioSlider .counter").text(itemP+"/"+itemN);	
	}
	if(state == "next") {
		if(!$(this).hasClass("disabled")){
			if(itemP + 4 > itemN) itemP += itemN-itemP;
			else itemP += 4;
			$("#portofolioSlider .counter").text(itemP+"/"+itemN);	
		}
	}
	if(state == "prev") {
		if(!$(this).hasClass("disabled")){
			if(itemP - 4 < 4) itemP -= itemP-4;
			else itemP -= 4;
			$("#portofolioSlider .counter").text(itemP+"/"+itemN);	
		}
	}
}

/* Start $.ScrollTo Plugin  */
/**
 * $.ScrollTo - Easy element scrolling using $.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/$scrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.$)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})($);
/* End $.ScrollTo Plugin  */

/* Make the tabbed menu */
$(document).ready(function() {
	$('#tabContainer .tabContent .viewAll').hide();
	$('#tabNav').show();
	//$('#tabNav .jcarouselPrev2, #tabNav .jcarouselNext2').hide();

	$('#tabHolder').width((parseInt($('#tabMask').width()+30) * $('#tabContainer .tabContent').length));
	
	$('#tabContainer .tabContent').width($('#tabMask').width());
			
	$("#tabNav .viewAll").append($($('#tabs li.active').find('a').attr('href')).find('.viewAll').html());	
	
	$('#tabMask').height($('#tab1').find('li').outerHeight()*4);
	
	$('#tabMenu #tab1 .jcarousel-clip').height($('#tab1').find('li').outerHeight()*4);
	//$('#tabMenu #tab2 .jcarousel-clip').height($('#tab2').find('li').outerHeight()*3);

	$('#tabs li').click(function () {
		if($(this).find('a').attr('href') == "#tab1") {
			var panelheight = $($(this).find('a').attr('href')).find('li').outerHeight()*4;
			//$('#tabNav .jcarouselPrev2, #tabNav .jcarouselNext2').hide();
			$('#tabNav .jcarouselPrev1, #tabNav .jcarouselNext1').show();

		} else {
			var panelheight = $($(this).find('a').attr('href')).find('li').outerHeight()*3;
			$('#tabNav .jcarouselPrev1, #tabNav .jcarouselNext1').hide();
			//$('#tabNav .jcarouselPrev2, #tabNav .jcarouselNext2').show();
		}
				
		$('#tabs li').removeClass('active');
		$(this).addClass('active');
		
		$('#tabMask').animate({'height':panelheight},{queue:false, duration:800});	
		$('#tabMask .jcarousel-clip').animate({'height':panelheight},{queue:false, duration:800});	
		
		$('#tabMask').scrollTo($(this).find('a').attr('href'), 800);
		
		$("#tabNav .viewAll").empty().append($($(this).find('a').attr('href')).find('.viewAll').html());	
				
		return false;		
	});
	
	$('#tab1').jcarousel({
        scroll: 5,
		vertical: true,
		animation: 1500,
		easing: 'easeOutExpo',
		initCallback:  tab1CarouselInit,
		buttonNextCallback: tab1CarouselNext,
		buttonPrevCallback: tab1CarouselPrev
    });	

});

function tab1CarouselInit(carousel) {
	$('#tabNav .jcarouselNext1').bind('click', function() {
		carousel.next();
		return false;
	});	
	$('#tabNav .jcarouselPrev1').bind('click', function() {
		carousel.prev();
		return false;
	});
};
function tab1CarouselNext(carousel, button, enabled) {
	enabled ? $('#tabNav .jcarouselNext1').removeClass("disabled") : $('#tabMenu .jcarouselNext1').addClass("disabled");
};
function tab1CarouselPrev(carousel, button, enabled) {
	enabled ? $('#tabNav .jcarouselPrev1').removeClass("disabled") : $('#tabMenu .jcarouselPrev1').addClass("disabled");
};

function tab2CarouselInit(carousel) {
	$('#tabNav .jcarouselNext2').bind('click', function() {
		carousel.next();
		return false;
	});	
	$('#tabNav .jcarouselPrev2').bind('click', function() {
		carousel.prev();
		return false;
	});
};
function tab2CarouselNext(carousel, button, enabled) {
	enabled ? $('#tabNav .jcarouselNext2').removeClass("disabled") : $('#tabMenu .jcarouselNext2').addClass("disabled");
};
function tab2CarouselPrev(carousel, button, enabled) {
	enabled ? $('#tabNav .jcarouselPrev2').removeClass("disabled") : $('#tabMenu .jcarouselPrev2').addClass("disabled");
};

$(document).ready(function(){
	/* Image Lightbox */
	$('.imageLightbox').nyroModal({});
});

// this is a fix for the jQuery slide effects
function slideToggle(el, bShow){
  var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");
  
  // if the bShow isn't present, get the current visibility and reverse it
  if( arguments.length == 1 ) bShow = !visible;
  
  // if the current visiblilty is the same as the requested state, cancel
  if( bShow == visible ) return false;
  
  // get the original height
  if( !height ){
    // get original height
    height = $el.show().height();
    // update the height
    $el.data("originalHeight", height);
    // if the element was hidden, hide it again
    if( !visible ) $el.hide().css({height: 0});
  }

  // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
  if( bShow ){
    $el.show().animate({height: height}, {duration: 1000});
  } else {
    $el.animate({height: 0}, {duration: 1000, complete:function (){
        $el.hide();
      }
    });
  }
}


String.prototype.trim = function() {
	return this.replace(/^\s*|\s*$/g, '');
}	
	
function newAjax() { 
	var xmlhttp=false; 
	try { // No IE
		//xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		$('divContenido').html();//Se reemplazo por jQuery
	}
	catch(e) { 
		try	{ // IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { 
			xmlhttp = false; 
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 
	return xmlhttp; 
}

function trim(cadena) {
	for(i=0; i<cadena.length; )	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}

function str_replace(haystack, needle, replacement) {
	var temp = haystack.split(needle);
	return temp.join(replacement);
}


function validaCorreo(valor) {
	var reg = /(^[a-zA-Z0-9._-]{1,30})@([a-zA-Z0-9.-]{1,30}$)/;
	if(reg.test(valor)) {
		return true;
	} else {
		return false;
	}
}




$(document).ready(function() { 
     $(this).bind("contextmenu", function(e) 
     { 
     
        e.preventDefault(); 
        alert("Propiedad de Zenso Technology S.A. de C.V.");
     }); 
 });
 
 
 
