function imageOver (i)
{
	var x=MM_findObj("tbl"+i)
	x.borderColor = "#FFFFFF"
}

function imageOut (i)
{
	var x=MM_findObj("tbl"+i)
	x.borderColor = "#3398CC"
}

function MM_preloadImages()
{ //v3.0
	var d=document;
	
	if(!d.MM_p)
		d.MM_p=new Array();
	
	if(d.images)
	{
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;

		for(i=0; i<a.length; i++)
		{
			if (a[i].indexOf("#")!=0)
			{
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
		}
	}
}

function MM_swapImgRestore()
{ //v3.0
	var i,x,a=document.MM_sr;
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
		x.src=x.oSrc;
}

function MM_findObj(n, d)
{ //v4.01
	var p,i,x;
	if(!d)
		d=document;
		
	if((p=n.indexOf("?"))>0&&parent.frames.length)
	{
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all)
		x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById)
		x=d.getElementById(n);
	return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	{
		if ((x=MM_findObj(a[i]))!=null)
		{
			document.MM_sr[j++]=x;
			if(!x.oSrc)
				x.oSrc=x.src;
			x.src=a[i+2];
		}
	}
}

function MM_openBrWindow(theURL,winName,features)
{ //v2.0
	window.open(theURL,winName,features);
}

function openwindow_mov(url)
{
	newWin=window.open(url,"newwin","width=160,height=40,scrollbars=no,resizable=no");
	newWin.focus();
}

function showBody(number)
{
	document.getElementById("more"+number).style.display = "none";
	$("#reviewtext"+number).slideToggle(500)
	document.getElementById("reviewtext"+number).style.display = "inline";
}

function hideBody(number)
{
	document.getElementById("more"+number).style.display = "inline";
	$("#reviewtext"+number).slideToggle(500)
	document.getElementById("reviewtext"+number).style.display = "none";
}

function toggleShow(id, hide)
{
	var elem = document.getElementById(id)
	hide |= false
	if (elem)
	{
		if (!elem.style.display || (!hide && elem.style.display == "none"))
			elem.style.display = "block"
		else
			elem.style.display = "none"
	}
}

var timer = new Array()
var timeout = 5000
var timerStarted = false

function restartTimer(id)
{
	timerStarted = false
	timer[id] = new Date()
}

function toggleTimeout(id)
{
	var now = new Date()
	if (timerStarted && ((timer[id] && (timer[id] <= now - timeout)) || !timer[id]))
	{
		toggleShow(id, true)
	}
}

function startCountdown(id)
{
	timer[id] = new Date()
	setTimeout("toggleTimeout('"+id+"')",timeout)
	timerStarted = true
}

function darkenImage(id,ht)
{
	res = document.getElementById(id)
	if (res)
	{
		res.style.height = ht+"px"
		res.style.width = ht+"px"
		res.style.cursor = "pointer"
	}
}

function lightenImage(id)
{
	res = document.getElementById(id)
	if (res)
	{
		res.style.height = "0px"
		res.style.width = "0px"
		res.style.cursor = "default"
	}
}


// Carousel related:
function mycarousel_initCallback(carousel)
{
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#carousel-releases').jcarousel({
        // Configuration goes here
        auto: 5,
        wrap: 'last',
        animation: 'slow',
        initCallback: mycarousel_initCallback
    });
});

//Slideshow related:
$(document).ready(function()
{
	//Execute the slideShow, set 5 seconds for each images
	slideShow(5000);
});

function slideShow(speed)
{
	//append a LI item to the UL list for displaying caption
	$('ul.gallery').append('<li id="gallery-caption" class="caption"><div class="gallery-caption-container"><h3></h3><p></p></div></li>');
	//Set the opacity of all images to 0
	$('ul.gallery li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.gallery li').first().css({opacity: 1.0});
	
	//Get the caption of the first image from title attribute and display it
	$('#gallery-caption h3').html($('ul.gallery a').first().find('img').attr('title'));
	$('#gallery-caption p').html($('ul.gallery a').first().find('img').attr('alt'));
	
	//Display the caption
	$('#gallery-caption').css({opacity: 0.7, bottom:-40});
	
	//Call the gallery function to run the slideshow
	var timer = setInterval('gallery()',speed);
	
	//pause the slideshow on mouse over
	$('ul.gallery').hover(
		function ()
		{
			clearInterval(timer);
			$('#gallery-caption').stop(true,false).animate({bottom:0}, 500)
		},
		function ()
		{
			timer = setInterval('gallery()',speed);
			$('#gallery-caption').stop(true,false).animate({bottom:-40}, 500)
		}
	);
}

function gallery()
{
	//if no IMGs have the show class, grab the first image
	var current = ($('ul.gallery li.gallery-show') ? $('ul.gallery li.gallery-show') : $('ul.gallery li').first());
	
	if ($('ul.gallery li').length > 2)
	{
		//Get next image, if it reached the end of the slideshow, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().attr('id') == 'gallery-caption')? $('ul.gallery li').first() :current.next()) : $('ul.gallery li').first());
		
		//Get next image caption
		var title = next.find('img').attr('title');
		var desc = next.find('img').attr('alt');
		
		//Set the fade in effect for the next image, show class has higher z-index
		next.css({opacity: 0.0}).addClass('gallery-show').animate({opacity: 1.0}, 1000);
		
		// Change the caption:
		$('#gallery-caption h3').html(title);
		$('#gallery-caption p').html(desc);
		
		//Hide the current image
		current.animate({opacity: 0.0},1000).removeClass('gallery-show');
	}
}

function startCartUpdate(id)
{
	setInterval("getCartUpdate('"+id+"')",30000)
}

function getCartUpdate(id)
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			if (xmlhttp.responseText != "**nochange**")
				document.getElementById(id).innerHTML=xmlhttp.responseText;
		}
	}
	cartCstr =""
	if (cartC=document.getElementById('cartstring'))
		cartCstr = cartC.innerHTML
	xmlhttp.open("POST","/Web/getCart.asp",true)
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded")
	xmlhttp.send("contents="+cartCstr)
}
