$(document).ready(function(){

});

function changeNavPic(id) {
	if(	$('#navImgHolder img:visible').attr('src') != $('#navImgHolder img#' + id).attr('src') ) {
		$('#navImgHolder img:visible').fadeOut(100);
		$('#navImgHolder img#' + id).fadeIn(100);
	}
}

function scrollToTop() {
	window.scroll(0,0);
	window.scrollTo(0,0);
	window.scrollTopTop();
	document.body.scrollTop = 0;
	location.href='#1';
	//alert("what?");
	return true;
}

function initMisc(d,ob) {
	dWidth = $('#' + d).width() + 20;
	dHeight = $('#' + d).height() + 20;
	$('body').append('<div class="prevOver" id="prevOverID" style="filter:alpha(opacity=75); -moz-opacity: 0.75; opacity: 0.75;"></div><div class="previewPane" style="width:' + dWidth + 'px; height:' + dHeight + 'px;"></div>');
	$('#' + d).prependTo('.previewPane');
	$('#' + d).show();
	$('.prevOver').click(function(){closeMisc(d,ob);});
	$('.previewPane').css('left', ($(window).width() - dWidth)/2 + 'px');
	if ( !(jQuery.browser.msie && jQuery.browser.version <= 7))  $('.previewPane').css('top', ($(window).height() - dHeight)/2 + 'px');
	else {
		$('html').css('overflow','hidden');	$('select').css('display','none');
		$('.previewPane').css('top', (($(window).height() - dHeight)/2 + (textpx = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)) + 'px');
	}
	$('.prevOver').fadeIn(200,function(){$('.previewPane').show();});
}

function initMiscEmail(d,ob) {
	dWidth = $('#' + d).width() + 20;
	dHeight = $('#' + d).height() + 20;
	$('body').append('<div class="prevOver" id="prevOverID" style="filter:alpha(opacity=75); -moz-opacity: 0.75; opacity: 0.75;"></div><div class="previewPaneEmail" style="width:' + dWidth + 'px; height:' + dHeight + 'px;"></div>');
	$('#' + d).prependTo('.previewPaneEmail');
	$('#' + d).show();
	$('.prevOver').click(function(){closeMisc(d,ob);});
	$('.previewPaneEmail').css('left', ($(window).width() - dWidth)/2 + 'px');
	if ( !(jQuery.browser.msie && jQuery.browser.version <= 7))  $('.previewPaneEmail').css('top', ($(window).height() - dHeight)/2 + 'px');
	else {
		$('html').css('overflow','hidden');	$('select').css('display','none');
		$('.previewPaneEmail').css('top', (($(window).height() - dHeight)/2 + (textpx = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)) + 'px');
	}
	$('.prevOver').fadeIn(200,function(){$('.previewPaneEmail').show();});
}


function closeMisc(d,ob) {
	if ( (jQuery.browser.msie && jQuery.browser.version <= 7)) {$('html').css('overflow',''); $('select').css('display','');}
	if (ob == "body") $('#' + d).appendTo('body');
	else $('#' + d).appendTo('#' + ob);
	$('#' + d).hide();
	$('.previewPane').remove();
	$('.prevOver').fadeOut(200,function(){$('.prevOver').remove();});
}

function closeMiscEmail(d,ob) {
	if ( (jQuery.browser.msie && jQuery.browser.version <= 7)) {$('html').css('overflow',''); $('select').css('display','');}
	if (ob == "body") $('#' + d).appendTo('body');
	else $('#' + d).appendTo('#' + ob);
	$('#' + d).hide();
	$('.previewPaneEmail').remove();
	$('.prevOver').fadeOut(200,function(){$('.prevOver').remove();});
}


function initPrev(f) {
	$('body').append('<div class="prevOver" id="prevOverID" style="filter:alpha(opacity=75); -moz-opacity: 0.75; opacity: 0.75;"></div><div class="previewPane"></div>');
	$('.prevOver').click(closePrev);
	$('.previewPane').css('left', ($(window).width() - 570)/2 + 'px');
	if ( !(jQuery.browser.msie && jQuery.browser.version <= 7))  $('.previewPane').css('top', ($(window).height() - 565)/2 + 'px');
	else {
		$('html').css('overflow','hidden');	$('select').css('display','none');
		$('.previewPane').css('top', (($(window).height() - 565)/2 + (textpx = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)) + 'px');
	}
	$('.prevOver').fadeIn(200,function(){$('.previewPane').show();loadPrev(f);});

}

function loadPrev(f) {
	$('.previewPane').load(f);
}

function switchPrev(f) {
	$('.previewPane .innards').fadeOut(200,function(){
		$('.previewPane').load(f);
		$('.previewPane').fadeIn(200);
	});
}

function closePrev() {
	if ( (jQuery.browser.msie && jQuery.browser.version <= 7)) {$('html').css('overflow',''); $('select').css('display','');}
	$('.previewPane').remove();
	$('.prevOver').fadeOut(200,function(){$('.prevOver').remove();});
}

function initMini(f) {
	$('body').append('<div class="prevOver" id="prevOverID" style="filter:alpha(opacity=75); -moz-opacity: 0.75; opacity: 0.75;"></div><div class="miniviewPane"></div>');
	$('.prevOver').click(closeMini);
	$('.miniviewPane').css('left', ($(window).width() - 250)/2 + 'px');
	if ( !(jQuery.browser.msie && jQuery.browser.version <= 7))  $('.miniviewPane').css('top', ($(window).height() - 250)/2 + 'px');
	else {
		$('html').css('overflow','hidden');	$('select').css('display','none');
		$('.miniviewPane').css('top', (($(window).height() - 250)/2 + (textpx = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)) + 'px');
	}
	$('.prevOver').fadeIn(200,function(){$('.miniviewPane').show();loadMini(f);});

}

function loadMini(f) {
	$('.miniviewPane').load(f);
}

function switchMini(f) {
	$('.miniviewPane .innards').fadeOut(200,function(){
		$('.miniviewPane').load(f);
		$('.miniviewPane').fadeIn(200);
	});
}

function closeMini() {
	if ( (jQuery.browser.msie && jQuery.browser.version <= 7)) {$('html').css('overflow',''); $('select').css('display','');}
	$('.miniviewPane').remove();
	$('.prevOver').fadeOut(200,function(){$('.prevOver').remove();});
}

function changeSwatch(id,c,i) {
	if ($('input#ShowProduct_ctl04_option0').val()!=id) {
		$('input#ShowProduct_ctl04_option0').val(id);
		if ( $('#product-thumbs div').length > 0 ) {
			$('#product-thumbs div:visible').hide();
			$('#product-thumbs img.selected').removeClass('selected');
			$('#product-thumbs div#' + c).show();
			$('#product-thumbs div#' + c + ' img[src=' + i.replace('/product/','/thumbs/') + ']').addClass('selected');
			curID =  $('#product-thumbs img.selected').attr('id');
		}else{
			curID = 'swatch' + id;
		}
	/*	if ($('span#prodMoreImg').length > 0) {
			currentClick = $('span#prodMoreImg').attr('onclick').substring($('span#prodMoreImg').attr('onclick').indexOf('\'')+1,$('span#prodMoreImg').attr('onclick').lastIndexOf('\''));
			if (currentClick.indexOf('&Src=') == -1) currentClick += '&Src=' + curID;
			else currentClick = currentClick.substring(0,currentClick.lastIndexOf('=')+1) + curID;
			$('span#prodMoreImg').attr('onclick','initPrev(\'' + currentClick + '\');')
		} */
		//$('#product-top').append('<img src="' + i + '" style="left:380px;" />');
		//$('#product-top img').animate({left:'-=380px'},'fast',function(){if($('#product-top img:first').attr('src')!=$('#product-top img:last').attr('src')) $('#product-top img:first').remove();  });
		
		$('#ProductImage').attr('src', i);
		
	}
}

function showPic(i,n) {
	if ($('#product-top img').attr('src').indexOf(i.toString()) == -1) {
	/*	currentClick = $('span#prodMoreImg').attr('onclick').substring($('span#prodMoreImg').attr('onclick').indexOf('\'')+1,$('span#prodMoreImg').attr('onclick').lastIndexOf('\''));
		if (currentClick.indexOf('&Src=') == -1) currentClick += '&Src=' + n;
		else currentClick = currentClick.substring(0,currentClick.lastIndexOf('=')+1) + n;
		$('span#prodMoreImg').attr('onclick','initPrev(\'' + currentClick + '\');') */
		$('#product-thumbs img.selected').removeClass('selected');
		$('#product-thumbs img#' + n).addClass('selected');
		
		//$('#product-top').append('<img src="' + i + '" style="left:380px;" />');
		//$('#product-top img').animate({left:'-=380px'},'fast',function(){if($('#product-top img:first').attr('src')!=$('#product-top img:last').attr('src')) $('#product-top img:first').remove();  });
		
		$('#ProductImage').attr('src', i);
		
	}
}

function changeCategorySwatch(c,id,i) {
	
		$('#' + id + ' img.selected').attr('src',$('#' + id + ' img.selected').attr('src').replace('-selected','-unselected'));
		$('#' + id + ' img.selected').removeClass('selected');
		$('#' + id + ' img#' + c).attr('src',$('#' + id + ' img#' + c).attr('src').replace('-unselected','-selected'));
		$('#' + id + ' img#' + c).addClass('selected');
		//$('#' + id + ' .imageHolder').append('<img src="' + i + '" style="left:191px;" />');
		//$('#' + id + ' .imageHolder img').animate({left:'-=191px'},150,function(){if($('#' + id + ' .imageHolder img:first').attr('src')!=$('#' + id + ' .imageHolder img:last').attr('src')) $('#' + id + ' .imageHolder img:first').remove();  });	
		$('#' + id + ' .imageHolder img:first').attr('src', i);

}

function changeLargeSwatch(c,i) {
	if ( $('#colorContainer img.selected').attr('id') != c ) {
		$('#colorContainer img.selected').attr('src',$('#colorContainer img.selected').attr('src').replace('-selected','-unselected'));
		$('#colorContainer img.selected').removeClass('selected');
		$('#colorContainer img#' + c).attr('src',$('#colorContainer img#' + c).attr('src').replace('-unselected','-selected'));
		$('#colorContainer img#' + c).addClass('selected');
		$('.views div:visible').hide();
		$('.views img.selected').removeClass('selected');
		$('.views div#' + c).show();
		$('.views div#' + c + ' img[src=' + i.replace('/product-large/','/thumbs/') + ']').addClass('selected');
		//$('.image').append('<img src="' + i + '" style="left:580px;" />');
		//$('.image img').animate({left:'-=580px'},'fast',function(){if($('.image img:first').attr('src')!=$('.image img:last').attr('src')) $('.image img:first').remove();  });
		$('#mainImage').attr('src', i);
	}
}

function showLargePic(i,n) {
	if ($('.image img').attr('src').indexOf(i.toString()) == -1) {
		$('.views img.selected').removeClass('selected');
		$('.views img#' + n).addClass('selected');
		//$('.image').append('<img src="' + i + '" style="left:580px;" />');
		//$('.image img').animate({left:'-=580px'},'fast',function(){if($('.image img:first').attr('src')!=$('.image img:last').attr('src')) $('.image img:first').remove();  });
		$('#mainImage').attr('src', i);
	}
}


function scrollToTop() {
	if (window.PageYOffset) window.PageYOffset = 0;
	if (document.documentElement) document.documentElement.scrollTop = 0;
	if (document.body) document.body.scrollTop = 0;
}

function fadeBlink(c) {
	if ( $('.' + c).css('display') == 'none' ) $('.' + c).fadeIn('fast',function(){fadeBlink(c);});
	else $('.' + c).fadeOut('fast',function(){fadeBlink(c);});
}