// Simple JavaScript Rotating Banner Using jQuery
// www.mclelun.com
var vCurrent = 0;
var vTotal = 0;
var vDuration = 8000;
var intInterval = 0;
var vGo = 1;


jQuery(document).ready(function() {	
	
	vTotal = $(".jqb_slides").children().size() -1;
	$(".jqb_info").text($(".jqb_slide").children().children().attr("title"));	
	intInterval = setInterval(fnLoop, vDuration);
	
	$("#btn_stop").click(function() {
		clearInterval(intInterval);
	});
	$("#btn_play").click(function() {
		fnChange();
	});	
	
	$("#btn_prev").click(function() {
		vGo = -1;
		fnChange();
	});
		
	$("#btn_next").click(function() {
		vGo = 1;
		fnChange();
	});
	


	
});

function fnChange(){
	clearInterval(intInterval);
	intInterval = setInterval(fnLoop, vDuration);
	fnLoop();
}

function fnLoop(){
	if(vGo == 1){
		vCurrent == vTotal ? vCurrent = 0 : vCurrent++;
	} else {
		vCurrent == 0 ? vCurrent = vTotal : vCurrent--;
	}
		
	$("#jqb_object").find(".jqb_slide").each(function(i) { 
		if(i == vCurrent){
			$(".jqb_info").text($(this).children().children().attr("title"));
			$(this).animate({ opacity: 'show', height: 'show' }, 100);
			
		} else {
			$(this).animate({ opacity: 'hide', height: 'hide' }, 100);
		}
	});
}






/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
 
    var $active = $('#slideshow IMG.active');
   if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval( "slideSwitch()", 5000 );
});



/////////
redireccion = function(destino){
		var H = 480; //screen.availHeight;
		var W = 640; //screen.availWidth;		
		var atributos = "channelmode=1,scrollbars=1,fullscreen=1,Top=0,Left=0,Width="+W+",Height="+H;
        var dominio ='www.excluciva.pe';
		if(destino == "chat"){
			
		window.open('http://www.perudesarrollo.org/webim/client.php?locale=sp&amp;url='+escape(document.location.href)+'&amp;referrer='+escape(document.referrer), 'webim', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,width=640,height=480,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;
			
		}else if(destino == "encomienda")	document.open("https://" + dominio + "/encomiendas","",atributos)
		else if(destino == "shop-online")  	document.open("https://" + dominio + "/online","",atributos)
   		else if(destino == "email")  		document.open("http://www.turismociva.com/email.php","",atributos)
        

}

$(function() {
/*	$(window).scroll(function(){

		
	});*/
	var distanceTop = $('#last').offset().top - $(window).height();
		
		if  ($(window).scrollTop() > distanceTop)
			$('#slidebox').animate({'right':'0px'},300);
		else 
			$('#slidebox').stop(true).animate({'right':'-490px'},100);	
			
	$('#slidebox .close').bind('click',function(){
		$(this).parent().remove();
	});
});
