var topslider = null;
var slidercount = 0;
var sliderwidth = 0;
var slidercurrent = 0;
var slidertimer = null;

Ext.onReady(function(){
	topslider = $("#front_top_slider");
    slidercount = topslider.find(".front_top_panel").size();
    if (slidercount > 0)
    {
    	if ($.browser.msie)
        {
    		topslider.find(".front_top_panel").each(function(){
    	    	$("#"+this.id+" img").each(function(){
		            this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src='"+ this.src +"')";
    	        });
	        });
        }
    	sliderwidth = topslider.find(".front_top_panel").width();
		slidertimer = setTimeout("changePanel();", 5000);
    }
	$("#photos").galleryView({
    	panel_width: 560,
        panel_height: 300,
        frame_width: 60,
        frame_height: 60,
        filmstrip_margin: 5,
        pause_on_hover: false
    });
    $("div#maincontent img").each(function(idx){
    	tmp = $(this).attr("src");
        tar = tmp.split(".");
        if (tar.length < 4)
        	return;
        tmp = tar[0]; 
        for (var i = 1; i < tar.length-2; i++)
        	tmp = tmp + "." + tar[i];
        tmp = tmp + "." + tar[tar.length-1];
    	$(this).wrap("<a href='"+tmp+"' />");//fancybox({});
        $(this).parent().fancybox({});
    });
});

function changePanel()
{
	$("#front_top_slider div:nth-child("+(slidercurrent+1)+")").fadeOut(1000);
	slidercurrent++;
    if (slidercurrent >= slidercount)
    	slidercurrent = 0;
	$("#front_top_slider div:nth-child("+(slidercurrent+1)+")").fadeIn(1000);
//	topslider.animate({ marginLeft: -(slidercurrent*sliderwidth) }, 5000, "easeInOutElastic");
	slidertimer = setTimeout("changePanel();", 5000);
}

function stopSlider()
{
	clearTimeout(slidertimer);
}
