var a_elements=new Array();
var a_slide_time=5;
var a_counter;

/* Cut! Only required features */
$(document).ready(function() {

	$(window).resize(function() {
		realignStyleElements();
	});


	//slideshow
	var a_num=0;
	if ($(".slider").length!=0){
		//prepare slides
		$("[vtype=slideshow-slide]").each( function(index) {		
			//set default
			if (a_num==0){
				$(".slider").css("background-image","url('"+$(this).attr("image")+"')");
				slider_active_slide($(this).get(0));
			}
			a_num++;
            
            $(this).bind("click",function(index){
                a_counter=a_slide_time;
                slider_active_slide($(this).get(0));
            });
		});
		
		a_counter=a_slide_time;
		setTimeout("change_slide()",1000);
	}

    //redraw elements
    realignStyleElements()

});



function realignStyleElements(){}


/* Regular slideshow */
function slider_active_slide(element){
	a_counter=a_slide_time;
	$("[vtype=slideshow-slide]").each( function(index) {
		$(this).attr("active","0");
        $(this).attr("class","slideshow-slide");
	});
	$(element).attr("active","1");
    $(element).attr("class","slideshow-slide-active");
	

    $(".slider").animate({
       opacity: 0.2
       },800, function (){
           $(".slider").css("background","url('"+$(element).attr("image")+"')");
           $(".slider").animate({opacity: 1},800,function () { });	
    });

	a_counter=a_slide_time;
}

function switch_slide(direction){
	var a_active,a_total;
	a_active=0; a_total=0;
	$("[vtype=slideshow-slide]").each( function(index) {
		if ($(this).attr("active")=="1") a_active=index; 
		a_total=index;
	});

	if (direction=="next"){
		if (a_active>=a_total) {
			slider_active_slide($("[vtype=slideshow-slide]").get(0));
		}else slider_active_slide($("[vtype=slideshow-slide]").get(a_active+1));
	}
}

function change_slide(){
	if (a_counter>0){
		a_counter--;
	} else{
		switch_slide("next");
	}
	setTimeout("change_slide()",1000);
}
