var transparentImage = "images/transparent.gif";

function fixTrans()
{
	if (typeof document.body.style.maxHeight == 'undefined') {

	var imgs = document.getElementsByTagName("img");
	
	for (i = 0; i < imgs.length; i++)
	{	
		if (imgs[i].src.indexOf(transparentImage) != -1)
		{
			return;
		}

		if (imgs[i].src.indexOf(".png") != -1)
			{
				var src = imgs[i].src;
				imgs[i].src = transparentImage;
				imgs[i].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
			}
		}	
	}
}

$(document).ready(function()
{
	fixTrans();
	$('.collections').each(function(){
		$('li.tile',this).hover( 
			function(){
				bg = $('a',this).attr('href');
				$('#tile-repeat').css({backgroundImage:'url('+bg+')'});
				$(this).addClass('active');
			}, 
			function(){
				$(this).removeClass('active');
			});							
	});
	
	$('#modal').jqm({
		zIndex: 3000, 
		overlay:75,
		//ajax: '@href', /* Extract ajax URL from the 'href' attribute of triggering element */
		//ajax: 'ajax.html',
		//target: t,
		//trigger:'.samples_modal',
		onShow: function(h)
			{
				h.o.fadeIn(500);
				h.w.fadeIn(500);
			},
		onHide: function(h) 
			{
				h.o.fadeOut(500);
				h.w.fadeOut(500,function() { if(h.o) h.o.remove(); });
				//h.w.slideUp("slow",function() { if(h.o) h.o.remove(); }); 
			} 
	});
	
	/* carousel */

	var children = $("#carousel_images").children();
	var width = children.length*817;
	$("#carousel_images").css({width:width+'px'});
	
	var next = Math.floor(width/817); //number of visible products at 1 time
	var count = 0;
	  
	$("#carousel_prev").click(function () {
		if(count > 0)
			{ 
				$("#carousel_images").animate({left:"+=817px"},"slow");
				count--;
			}
			
		return false;
	});  
		
	$("#carousel_next").click(function () { 
		if(count < next) 
			{
				$("#carousel_images").animate({left:"-=817px"},"slow");
				count++;    
			}
		//alert(next);
		return false;
	});	
	
});

	
function open_modal(path)
	{
		scrollTo(0,0);
		$('#modal_frame').attr({src:path});
		$('#modal').jqmShow();
		//return false;
	}

/*if (document.all && !window.opera)
	attachEvent("onload", fixTrans);*/
	


/*initCollections = function() {
	var navRoot = document.getElementById("collections");
	var lis = navRoot.getElementsByTagName("li");
	var mosaicoName = "";
	var collectionsClassName = navRoot.className;
	for (var i=0; i<lis.length; i++)
	{
		if (lis[i].parentNode.className == "collections")
		{
			lis[i].onmouseover = function()
			{
				navRoot.className = collectionsClassName + " " + this.className.replace("active", "");
				if (window.attachEvent && !window.opera) this.className += " hover";
			}
			lis[i].onmouseout = function()
			{
				navRoot.className = collectionsClassName;
				if (window.attachEvent && !window.opera) this.className = this.className.replace(" hover", "");
			}
		}
	}
}	
if (window.addEventListener)
	window.addEventListener("load", initCollections, false);
else if (window.attachEvent && !window.opera)
	window.attachEvent("onload", initCollections);*/