function openPopup( item_id, image_id )
{
	window.open( "/productimage.php?title=Product%20Image&selected=" + currentColor + "&data=" + getLargeImageData(), null, "width=515,height=550,status=0,help=no,top=" + (screen.availHeight-550)/2 + ",left=" + (screen.availWidth-515)/2 );
}

function openAdditionalImagesPopup( index )
{
	window.open( "/productimage.php?title=Additional%20Image&selected=" + index + "&data=" + getAdditionalImageData(), null, "width=515,height=430,status=0,help=no,top=" + (screen.availHeight-430)/2 + ",left=" + (screen.availWidth-515)/2 );
}

function openFansImagesPopup( index )
{
	window.open( "/productimage.php?title=Fans%20in%20Action%20Image&selected=" + index + "&data=" + getFansImageData(), null, "width=400px,height=300px,status=0,help=no,top=" + (screen.availHeight-300)/2 + ",left=" + (screen.availWidth-400)/2 );
}

function showColor( id ) {
	var i=0;
	currentColor = parseInt(id, 10);
	for (i=0; i<colorIds.length; i++) {
		if (parseInt(id, 10)==colorIds[i]) {
			break;
		}
	}
	var mainImage = document.getElementById("mainImage");
	mainImage.src = colorImages[i];
}

function addToShoppingCart()
{
	var s = $( '#size' ); 
	if ( s.attr('selectedIndex') == 0 ) { 
		s.addClass( 'error' );  
		alert( 'Size/color selection required' );
		return; 
	}
	$( '#addForm' ).submit(); 
}

var adding = false; 
var added = false; 
function addToWishList()
{
	if (added) 
		return; 
	if ( $( '#size' ).attr('selectedIndex') == 0 ) 
	{
		alert( 'You need to select a size or color before adding this to your wishlist!' ); 
		return; 
	}
	if (adding)
		return; 
	adding = true; 
	if ( userId == '' ) { 
		$( '#addForm' ).attr( 'action', '/wishlist.php' ); 
		$( '#addForm' ).submit(); 
	} else { 
		$.post("/wishlist.php", $("#addForm").serialize(),
			function(data) {
				if ( data.rc == 0 ) 
				{
					added = true; 
					alert( 'Item has been added to your wishlist!.' ); 
				}
				else
				{
					alert( data.rm ); 
					adding = false; 
				}
			}, "json");
	}
	return false; 
}

function move( dir )
{
	var largeImage = document.getElementById("largeImage");
	var currentIndex = -1;
	for (currentIndex=0; currentIndex<imageIds.length; currentIndex++) {
		if (imageIds[currentIndex]==currentId) {
			break;
		}
	}
	var nextIndex = -1;
	if (dir>0) {
		if (currentIndex+dir < imageIds.length) {
			nextIndex = currentIndex+dir;
			currentId = imageIds[nextIndex];
		} else {
			nextIndex = 0;
			currentId = imageIds[0];
		}
	} else {
		if (currentIndex+dir < 0) {
			nextIndex = imageIds.length-1;
			currentId = imageIds[imageIds.length-1];
		} else {
			nextIndex = currentIndex+dir;
			currentId = imageIds[nextIndex];
		}
	}
	document.getElementById('productImg').src = '/' + imageSrcs[nextIndex];
	document.getElementById('lbImg').href = xlimageSrcs[nextIndex];
	if (xlimageSrcs[nextIndex] == "") {

	} else {

	}
}

$(document).ready( function() { 
	$( '#prodGalleryImgBox' ).css( 'overflow', 'hidden' ); 
	var galUp = $( '#moveGalUp' ); 
	galUp.css( 'display', 'block' ); 
	galUp.mouseover( function() { this.src = '/i/prod_gal_up_over.jpg'; }); 
	galUp.mouseout( function() { this.src = '/i/prod_gal_up.jpg'; }); 
/*
	galUp.mouseover( function() { this.src = '/i/prod_gal_down_over.jpg'; }); 
	galUp.mouseout( function() { this.src = '/i/prod_gal_down.jpg'; }); 
*/
	var galDown = $( '#moveGalDown' ); 
	galDown.css( 'display', 'block' ); 
	galUp.click( moveUp ); 
	galDown.click( moveDown );
	galDown.mouseover( function() { this.src = '/i/prod_gal_down_over.jpg'; }); 
	galDown.mouseout( function() { this.src = '/i/prod_gal_down.jpg'; }); 
/*
	galDown.mouseover( function() { this.src = '/i/prod_gal_up_over.jpg'; }); 
	galDown.mouseout( function() { this.src = '/i/prod_gal_up.jpg'; }); 
*/

	$( '#wishListLink' ).click(addToWishList); 
	$( '#notifyEmailButton' ).mouseover( function() { this.src='/i/go_over.jpg'; }); 
	$( '#notifyEmailButton' ).mouseout( function() { this.src='/i/go.jpg'; }); 	
	$( '#addToCart' ).mouseover( function() { this.src='/i/addtocart_over.jpg'; }); 
	$( '#addToCart' ).mouseout( function() { this.src='/i/addtocart.jpg'; }); 
	$( '#emailToSubmit' ).mouseover( function() { this.src='/i/sendnow_over.jpg'; }); 
	$( '#emailToSubmit' ).mouseout( function() { this.src='/i/sendnow.jpg'; }); 
	var prev = $( '#prev' );
	if ( prev.attr('src').indexOf( 'disabled' ) < 0 )
	{
		prev.mouseover( function() { this.src = '/i/prev_over.gif'; });
		prev.mouseout( function() { this.src = '/i/prev.gif'; }); 
	}
	var next = $( '#next' );
	if ( next.attr('src').indexOf( 'disabled' ) < 0 )
	{
		next.mouseover( function() { this.src = '/i/next_over.gif'; });
		next.mouseout( function() { this.src = '/i/next.gif'; }); 
	}
	$( 'a.prodImages' ).fancybox(); 
}); 



function butOver()
{
	this.style.backgroundColor = '#fffffc';
}

function butOut()
{
	this.style.backgroundColor = '#f0f0f0';
}

function tweetRequest( url )
{
	shortenUrl( url, tweet ); 
}

function tweet( url ) 
{
	$( '#status' ).attr( 'value', 'Check out ' + $( '#item_name' ).attr( 'value' ) + ' from @splitreason_com ' + url + ' !' ); 
	$( '#tweetForm').submit(); 
}
