function x(){

	//console.log('level 1');

	$(this).stopTime();leri

	$(this).find('li').css('opacity', 1);

	i=1;

	$(this).children('.active').everyTime(2000, function(){

		//console.log('level 2');

		if(i<=$(this).children().length)

	    {

	    	$(this).children('li:nth-child('+i+')').animate({'opacity':0}, 900);

	    }

	    else

	    {

	    	//this is a UL

	        $(this).stopTime(); //REMOVE THIS TIMER

	        $(this).parent().everyTime(10000, x); //RESTART THE MAIN TIMER

			

	        if($(this).next().is('ul'))

	        {

	        	$(this).next().addClass('active').css('z-index', 10);

	        	$(this).removeClass('active').css('z-index', 0);

	        }

	        else

	        {

				$(this).siblings().first().addClass('active').css('z-index', 10);

				$(this).removeClass('active').css('z-index', 0);

	        }

	        $(this).css('z-index', 0);

	        

	    }

	    i++;

	});

}

function startSlide(){

	

	$(this).stopTime();

	

	var $active = $(this).find('.active');

	

	if($active.next().is('ul'))

    {

    	$active.next().addClass('next');

   		//console.log('next');

    }

    else

    {

		$(this).siblings().first().addClass('next');

   		//console.log('first');

    }

    

    var $next = $(this).find('.next');

    

    //DO SOMETHING WITH $next HERE

    

    $next.children().css('opacity', 0); //TEMPORARILY HIDE LI ELEMENTS

    $next.css({'background':'transparent'}); //MAKE IT TRANSPARENT

    $next.css("z-index", 2); //PUT NEXT ON TOP

    

    $active.css("z-index", 1); //PUT CURRENT IN THE BOTTOM

    $active.css({'background':'#000'}, 900); //ANIMATE BACKGROUND

    $active.children().animate({'opacity':0.3}); //ANIMATE

    

    i=1;

    

    $next.everyTime(2000, function(){

    	//$(this) is $next

    	if(i<=$(this).children().length)

    	{

			$(this).children('li:nth-child('+i+')').animate({'opacity':1}, 900);

    	}

    	else

    	{

    		 $next.stopTime();

    		 $(this).parent().everyTime(10000, startSlide); 

    	}

		i++;

    });

   

    

    

    //THEN SWAP IT CAUSE NEXT IS VISIBLE NOW

    $next.removeClass('next').addClass('active');

    $active.removeClass('active').addClass('next');

    

}

jQuery.fn.extend({

	

	fadeAny: function() {

		

		$(this).children().first().addClass('active');

		$(this).everyTime(10000, x);

		

	},

	

	fadeAnyBetter : function()

	{

		

		$(this).children().first().addClass('active');

		$(this).everyTime(10000, startSlide);

		

	}

	

});



$(document).ready(function(){



	$('#wrap').fadeAnyBetter();

	

	var options = {

        insert : '#imgslideshow',

        history : false,

        onImage : function(image) {},

        onThumb : function(image) {image.css('display','none').fadeIn();},

	};



	$('ul#galleria').galleria(options);

	$('div#prev > a').click(function(){

		$.galleria.prev();

	});

	$('div#next > a').click(function(){

		$.galleria.next();

	});

	

    if ($("input#searchBoxInput").val().length > 0)

        $("label[for=searchBoxInput]").hide();

    

    $("label#lbsearchBoxInput").click(function() {

        inputname = $(this).attr("for");

        $("input#" + inputname).focus();

        $(this).hide();

    });

    

    $("input#searchBoxInput").focus(function() {

        labelforname = $(this).attr("id");

        $("label[for=" + labelforname + "]").hide();

    });

    

    $("input#searchBoxInput").blur(function() {

        labelforname = $(this).attr("id");

        if($(this).val().length <= 0)

            $("label[for=" + labelforname + "]").show();

    });

	

});

$(document).ready(function(){
	$('#leftcol #original_content p img').css('max-width','579px');
});

$(window).load(function() {

	function onAfter(curr, next, opts, fwd) {

		var heighto = $(this).height();

		$(this).parent().animate({height: heighto});

	}

	

	$('.wordcycle').cycle({

		speed: 'slow',

		fx: 'fade',

		timeout: 0,

		pause: 0,

		next: 'null',

		prev: 'null',

		after: onAfter,

		pager: '#naviga',

		pagerAnchorBuilder: function(idx, slide) { 

		var imgsrcs = $('img',slide).attr('src');

			return '<li><a href=\"#\" title=\"\"><img class=\"slide\" src=\"'+imgsrcs+'\" alt=\"<?php echo the_title();?>\" style="width: 105px;"/></a></li>'; 

		}

	});

		

	$('#naviga').jcarousel({
		visible: 5
	});

	

	$('img.slide').scaleImage({
		parent: "li",
		scale: 'fill'
	});

});
