var drieccion="/wp/wp-content/themes/cookiebox/";


this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

(function($) {

    $.fn.innerfade = function(options) {
        return this.each(function() {   
            $.innerfade(this, options);
        });
    };

    $.innerfade = function(container, options) {
        var settings = {
        		'animationtype':    'fade',
            'speed':            'normal',
            'type':             'sequence',
            'timeout':          2000,
            'containerheight':  'auto',
            'runningclass':     'innerfade',
            'children':         null
        };
        if (options)
            $.extend(settings, options);
        if (settings.children === null)
            var elements = $(container).children();
        else
            var elements = $(container).children(settings.children);
        if (elements.length > 1) {
            $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
            for (var i = 0; i < elements.length; i++) {
                $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
            };
            if (settings.type == "sequence") {
                setTimeout(function() {
                    $.innerfade.next(elements, settings, 1, 0);
                }, settings.timeout);
                $(elements[0]).show();
            } else if (settings.type == "random") {
            		var last = Math.floor ( Math.random () * ( elements.length ) );
                setTimeout(function() {
                    do { 
												current = Math.floor ( Math.random ( ) * ( elements.length ) );
										} while (last == current );             
										$.innerfade.next(elements, settings, current, last);
                }, settings.timeout);
                $(elements[last]).show();
						} else if ( settings.type == 'random_start' ) {
								settings.type = 'sequence';
								var current = Math.floor ( Math.random () * ( elements.length ) );
								setTimeout(function(){
									$.innerfade.next(elements, settings, (current + 1) %  elements.length, current);
								}, settings.timeout);
								$(elements[current]).show();
						}	else {
							alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
						}
				}
    };

    $.innerfade.next = function(elements, settings, current, last) {
        if (settings.animationtype == 'slide') {
            $(elements[last]).slideUp(settings.speed);
            $(elements[current]).slideDown(settings.speed);
        } else if (settings.animationtype == 'fade') {
            $(elements[last]).fadeOut(settings.speed);
            $(elements[current]).fadeIn(settings.speed, function() {
							removeFilter($(this)[0]);
						});
        } else
            alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
        if (settings.type == "sequence") {
            if ((current + 1) < elements.length) {
                current = current + 1;
                last = current - 1;
            } else {
                current = 0;
                last = elements.length - 1;
            }
        } else if (settings.type == "random") {
            last = current;
            while (current == last)
                current = Math.floor(Math.random() * elements.length);
        } else
            alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
        setTimeout((function() {
            $.innerfade.next(elements, settings, current, last);
        }), settings.timeout);
    };

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
	if(element.style.removeAttribute){
		element.style.removeAttribute('filter');
	}
}/*---------------------------------------------------------------------------------------------------------------------------------------------------------*/


function resetGalleta(){
	$('#1').css("background", "url("+drieccion+"img/galleta1-b.jpg) 0 500px no-repeat");
	$('#2').css("background", "url("+drieccion+"img/galleta2-b.jpg) 0 500px no-repeat");
	$('#3').css("background", "url("+drieccion+"img/galleta3-b.jpg) 0 500px no-repeat");
	$('#4').css("background", "url("+drieccion+"img/galleta4-b.jpg) 0 500px no-repeat");
	$('#5').css("background", "url("+drieccion+"img/galleta5-b.jpg) 0 500px no-repeat");
	$('#6').css("background", "url("+drieccion+"img/galleta6-b.jpg) 0 500px no-repeat");
	$('#7').css("background", "url("+drieccion+"img/galleta7-b.jpg) 0 500px no-repeat");
	$('#8').css("background", "url("+drieccion+"img/galleta8-b.jpg) 0 500px no-repeat");
	$('#9').css("background", "url("+drieccion+"img/galleta9-b.jpg) 0 500px no-repeat");
	$('#10').css("background", "url("+drieccion+"img/galleta10-b.jpg) 0 500px no-repeat");
	$('#11').css("background", "url("+drieccion+"img/galleta11-b.jpg) 0 500px no-repeat");
}

function updateSlide(){
	var actual=$('#currentSlide').val();
	var total=$('#totalSlide').val();
	if(actual==total){
		var sig=1;
	}else{
		var sig=parseInt(actual)+1;
	}
	document.getElementById("currentSlide").value=sig;
	$("#menu_"+sig+"").trigger('click');
}
function updateSlide2(){
	var actual=$('#currentSlide').val();
	var total=$('#totalSlide').val();
	if(actual==1){
		var sig=total;
	}else{
		var sig=parseInt(actual)-1;
	}
	document.getElementById("currentSlide").value=sig;
	$("#menu_"+sig+"").trigger('click');
}

$(document).ready(function() {
  $(".footer_links_c").click(function () {
    $(".footer_links").slideToggle("slow", function () {});
	return false;
  });
  $("#servicios").click(function () {
    $("#servicios_anidado").slideToggle("slow", function () {});
    $("#flecha").toggle();
	return false;
  });
  $("#boxes").click(function () {
    $("#boxes_anidado").slideToggle("slow", function () {});
    $("#flecha4").toggle();
	return false;
  });
  $("#pulso").click(function () {
    $("#pulso_anidado").slideToggle("slow", function () {});
    $("#flecha2").toggle();
	return false;
  });
  $("#contacto").click(function () {
    $("#contacto_div").slideToggle("slow", function () {});
	if($("#contacto").hasClass("active")){
		$("#contacto").removeClass("active");
	}else{
		$("#contacto").addClass("active");
	}
    $("#flecha3").toggle();
	return false;
  });
  $(".galleta a").click(function () {
//  	resetGalleta();
  	var ide=$(this).attr("id");
	$(".galleta a#"+ide+"").css("background-image", "url("+drieccion+"img/galleta"+ide+"-b.jpg)");
	$(".galleta a").removeClass("galletaactiva");
	$(".galleta a#"+ide+"").addClass("galletaactiva");
    $(".opinionesdiv").fadeOut(500, function () {
		$(".opinionesdiv").html($("#opinion"+ide+"").html())
		$(".opinionesdiv").fadeIn(500);
	});
	return false;
  });
  
	//Get the height of the first item
	$('#mask').css({'height':$('#panel-1').height()});	
	
	//Calculate the total width - sum of all sub-panels width
	//Width is generated according to the width of #mask * total of sub-panels
	$('#panel').width(parseInt($('#mask').width() * $('#panel div').length));
	
	//Set the sub-panel width according to the #mask width (width of #mask and sub-panel must be same)
//	$('#panel div').width($('#mask').width());
	
	//Get all the links with rel as panel
	$('a[rel=panel]').click(function () {
			
		//Get the height of the sub-panel
		var panelheight = $($(this).attr('href')).height();
		
		//Set class for the selected item
		$('a[rel=panel]').removeClass('selected');
		$(this).addClass('selected');
		
		//Resize the height
		$('#mask').animate({'height':panelheight},{queue:false, duration:500});			
		
		//Scroll to the correct panel, the panel id is grabbed from the href attribute of the anchor
		$('#mask').scrollTo($(this).attr('href'), 800);		
		
		//Discard the link default behavior
		return false;
	});
	
	
	// picture hover zoom
	$('.zoom-parent').mouseenter(function(e) {
		$(this).find('.image-zoom').stop(true, true).fadeTo(400, 1);
	}).mouseleave(function(e) {
		$(this).find('.image-zoom').stop(true, true).fadeTo(400, 0);
	});
	$('a.zoombox').zoombox();
					$('.rotator, .rotator2').innerfade({
						animationtype: 'fade',
						speed: 1000,
						timeout: 10000,
						type: 'random',
						containerheight: '613px'
					});
	screenshotPreview();

});
