jQuery(function($)
{
	/*try { $(document).pngFix(); } catch(e) {}*/
	var isFrontpage = ($('body').attr('id') == 'frontpage');
	
	var slideshowItems = [];
	var bannerItems = [];
	if(isFrontpage)
	{	
		slideshowItems = $('#banners-dynamic a:has(img.imgSmall)');
		bannerItems = $('#banners-dynamic a:has(img.imgLarge)');
	}
	else
	{
		slideshowItems = $('#detail img.imgSmall');
		bannerItems = $('#detail img.imgLarge');
	}	
	
	var hasSlideshowItems = slideshowItems.length > 0;	
	var hasBannerItems = bannerItems.length > 0;	
	
	if(hasSlideshowItems)
	{
	    if(isFrontpage)
    	{
    	    //slideshowItems = slideshowItems.slice(0, 1);
    	    //slideshowItems = $(slideshowItems.get().sort(function()
    	    //{ 
            //  return Math.round(Math.random()) - 0.5;
            //}).slice(0, MAX_ITEMS || 10));
        }
	
		slideshowItems.appendTo($('#banner-small').empty());
		slideshowItems.wrapAll('<div class="scrollable simple-scrollable"><div class="items"></div></div>');
	}
	
	if(hasBannerItems)
	{
		bannerItems.appendTo($('#banner-big').empty());
		//bannerItems.wrapAll('<div class="scrollable simple-scrollable"><div class="items"></div></div>');		
	}
	
	if(isFrontpage)
	{
		// (frontpage) remove linebreaks from banners
		$('#banners-dynamic a:has:not(img.imgMedium)').remove();
		$('#banners-dynamic br').remove();
		$('#banners-dynamic p').html($.shuffle($('#banners-dynamic a')));
	}
	
	var doSlideshowLoop = slideshowItems.length > 1;
		
	// if has simple-scrollable
	// (for default pages)
	$('div.simple-scrollable')
	.after('<div class="navi"></div>')
	.scrollable(
	{
		size: 1,
		loop: doSlideshowLoop,
		interval: 5000, 
		speed: 600, 	
		onBeforeSeek: doFadeOut, 
		onSeek: doFadeIn
	});
	
	// if has rich-scrollable
	// (for news pages)
	$('div.rich-scrollable')
	.after('<div class="navi"></div>')
	.scrollable(
	{ 
		size: 1, 
		items: '#richitems',  
		hoverClass: 'hover',
		loop: true,
		interval: 5000, 
		speed: 600,		
		onBeforeSeek: doFadeOut, 
		onSeek: doFadeIn
	});

	
	
	// when seek starts make items little transparent 
	function doFadeOut() { this.getItems().fadeTo(300, 0.2); }
	
	// when seek ends resume items to full transparency 
	function doFadeIn() { this.getItems().fadeTo(300, 1); }
	
	/*applyPNGFix();*/
});


function applyPNGFix()
{
	// ie6 or 5
	if($.browser.msie && $.browser.version < 7) 
	{
		// var blankImg = "images/blank.gif";
		$("img").each(function()
		{
			var src = $(this).attr('src');
			if(src.match(/png$/i))
			{
				$(this).css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')").attr("src", blankImg);
			}
		});
		$("a, #punch-hole, div.section-separator").each(function()
		{
			var bg = $(this).css("backgroundImage");
			if(bg.match(/^url[("']+(.*\.png)[)"']+$/i))
			{
				bg = RegExp.$1;
				$(this).css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bg + "', sizingMethod='crop')").css("backgroundImage", "none");
			}
		});
	}
}
