// JavaScript Document

var siteWidth = 825;
var siteHeight = 620;
var bottomOffset = 128;
var selCollection = 'none';
var expose;

$(document).ready(function(){
	
	$.ajaxSetup({
		url: "_konstrukt/ajax.gateway.php",
		global: false
	});

	rebind();
	
	$('.hover').imghover({suffix: '_o'});
	$('.back').click(function() { history.go(-1);  return false; });
	$('a.submit').click(function() { $(this).closest('form').submit(); return false; });
	$('.print').click(function() { window.print(); return false; });
	$('.redirector').click(function() { if ($(this).attr('url')) window.location.href = $(this).attr('url'); return false; });
	
	$('.rad').inputReplace('radio');
	$('.incrementer').inputReplace('incrementer');
	$('.cartQty').inputReplace('cartQty');

	$('.thumb').click(function() {
        flippingBook.getFlippingBookReference().flipGotoPage($(this).attr('rel'));
        return false;
    });

	$('#preloader').height($(window).height());
	
	if (($(window).height()+bottomOffset) <= siteHeight) {
		//$('#homeFeatures').css({'marginTop':($(window).height() - bottomOffset)});
	}
	
	preloadBG();
	
	$(".jqzoom").jqzoom({
		title: false,
	    zoomWidth: 230,
	    zoomHeight: 313,
		position: "right"
	});
	
	$(".faqs.sections a").click(function() {
		var thisObj = this;
		
		$.scrollTo($(thisObj).attr('href'), 1000, { onAfter:function(){
			//$($(thisObj).attr('href')).css({backgroundColor:'#000000'});
			/*
			$($(thisObj).attr('href')).animate({ 
				color: '#000000',
				fontSize: "1em"
			}, 500 );
			*/
			/*expose = $($(thisObj).attr('href')).expose({
				api: true,
				loadSpeed: 'normal',
				closeSpeed: 'fast',
				color: '#666', 
				opacity: 0.7,
				onLoad: function() { 
					$($(thisObj).attr('href')).addClass('faqExpose'); 
				} ,
				onClose: function() { 
					$($(thisObj).attr('href')).removeClass('faqExpose'); 
				} 
			});
			expose.load();*/
		}});
		
		return false;
	});
	
	$("a.scrollBtn").click(function() {
		var thisObj = this;
		$.scrollTo($(thisObj).attr('href'), 500);
		//if (expose) expose.close();
		return false;
	});
	
	$('.forgot').click(function() {
		$('#divLogin').toggle('fast');
		$('#divForgot').toggle('fast');
		return false;
	});
	
	$('.catBtn').click(function(){
		
		if ($('#catalogue').hasClass('opened')) {
			$('#flash-layer').hide();
			flashRequest('divContract');
			$('#catalogue').removeClass('opened');
			$('#catalogue').stop().animate( {height:'35px'}, 500, "linear");
		} else {
			$('#catalogue').addClass('opened');
			$('#flash-video').hide();
			$('#catalogue').stop().animate( {height:'120px'}, 500, "linear", function(){
			});
		}
		$(this).blur();
        return false;
	});

	$('#catalogue ul li a').click(function() {
		//flashRequest('divContract');
		//flashRequest('collection');
		selCollection = $(this).attr('rel');
		
		if ($('#flash-layer').is(':visible')) {
			flashRequest('collection');
		} else {
			$('#flash-layer').show();
			doFlashPos('#flash-layer');
		}
		$(this).blur();
        return false;
	});
	
	$('.flash-video').click(function(){
		$('#flash-layer').hide();
		$('#flash-video').show();
		doFlashPos('#flash-video');
		$(this).blur();
        return false;
	});

	$('.skip-intro').click(function(){
		$('#flash-video').fadeOut('fast', function() { $(this).remove(); });
        setCookie('skip',1,14);
        return false;
	});

	//$(window).resize(function(){
		//$('#colOne').animate( {height:$(window).height()}, 500);
	//	doFlashPos('#flash-layer');
		//doFlashPos('#flash-video');
	//});
	
	// menu expander
	$('.parent').click(function() {
		if (!$(this).next('.child').is(':animated')) {
			if ($(this).next('.child').hasClass('opened')) {
				$(this).next('.child').slideUp(200).removeClass('opened')
			} else {
				//alert($(this).closest('.child').attr('show'));
				//$('.child').removeClass('opened').slideUp(200);
				$(this).next('.child').slideDown(500).addClass('opened');
			}
		}
		$(this).blur();
        return false;
	});
	
	$('#products .item, #detailArea .imageOptions .item, #detailArea .alsoLike .item, #colThree .recent .body .item').hover( 
		function() { $(this).prepend('<div class="hover"></div>'); },
		function() { $('.hover', $(this)).remove(); }
	);
	
	$('.rowOver').hover(
		function(e) {
			$(this).addClass('rowHover');
		},
		function(e) {
			$(this).removeClass('rowHover');
		}
	);
	$('.rowOver').click(function() {
		window.location.href = $('a:first',$(this)).attr('href');
	});
	
	$('#detailArea .imageOptions a').click(function() {
		$('#detailArea .image a').attr('href', $(this).attr('image'));
		$('#detailArea .image img').hide().attr('src', $(this).attr('href')).fadeIn();
		$(this).blur();
        return false;
	});
	
	$('div', '#storeCountries, #storeStates, #storeCities').hover( 
		function() { $(this).addClass('hover'); },
		function() { $(this).removeClass('hover'); }
	);
	
	$('#storeCountries a').live('click', function() {
		var storeStates = '.c-'+$(this).attr('countryId');
		$('div','#storeCountries').removeClass('selected');
		$(this).closest('div').addClass('selected');
		$('div', '#storeStates, #storeCities, #storeLocations').hide('fast');
		$(storeStates, '#storeStates').show('fast');
		$(this).blur();
		$('#flashVideoBox').show();
        return false;
	});
	
	$('#storeStates a').live('click', function() {
		var storeCities = '.s-'+$(this).attr('state');
		$('div','#storeStates').removeClass('selected');
		$(this).closest('div').addClass('selected');
		$('div', '#storeCities, #storeLocations').hide('fast');
		$(storeCities, '#storeCities').show('fast');
		$(this).blur();
		$('#flashVideoBox').show();
        return false;
	});
	
	$('#storeCities a').live('click', function() {
		$('#flashVideoBox').hide();
		var storeLocations = '.c-'+$(this).attr('countryId')+'.s-'+$(this).attr('state')+'.t-'+$(this).attr('city');
		$('div','#storeCities').removeClass('selected');
		$(this).closest('div').addClass('selected');
		$('div', '#storeLocations').hide('fast');
		$(storeLocations, '#storeLocations').show('fast');
		$(this).blur();
        return false;
	});
	
	
	$('#frmProduct').submit(function(index, domEle) {
		
		var thisObj = this;
		
		$.ajax({
			type: "POST",
			data: "func=doCart&frmFunc=addItem&"+$(thisObj).serialize(),
			cache: false,
            dataType: "json",
			beforeSend: function(result) {
				//$(thisObj).find('.ajaxResult').empty();
				$('.result', thisObj).fadeOut('fast').empty();
			},
			success: function(data, textStatus) {
				if (data.error) {
					alert(data.error);
				} else {
					$('.cItemCount').html(data.itemCount);
					$('.cTotal').html('$'+data.subtotal);
					$('.result', thisObj).html(data.html).fadeIn('fast');
				}
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				alert('Error: '+textStatus);
			}
		});
		
        return false;
		
	});
	
	$('#cart .remove a').click(function() {
		
		var thisObj = this;
		var confirmMsg = ($(thisObj).attr('confirm')) ? $(thisObj).attr('confirm') : 'Are you sure you wish to continue?';
		
		if (confirm(confirmMsg)) {
		
			$.ajax({
				type: "POST",
				data: "func=doCart&frmFunc=removeItem&size="+$(thisObj).attr('itemCode'),
				cache: false,
				dataType: "json",
				beforeSend: function(result) {
				},
				success: function(data, textStatus) {
					if (data.error) {
						alert(data.error);
					} else {
						$(thisObj).closest('tr').fadeOut('fast').remove();
						$('#cart .total').html(data.total);
						$('.cItemCount').html(data.itemCount);
						$('.cTotal').html(data.total);
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					alert('Error: '+textStatus);
				}
			});
			
		}
		return false;
	});
	
	$('#cart .quantity input').change(function() {
		
		var thisObj = this;
		
		$.ajax({
			type: "POST",
			data: "func=doCart&frmFunc=editItem&size="+$(thisObj).attr('itemCode')+"&quantity="+$(thisObj).val(),
			cache: false,
			dataType: "json",
			beforeSend: function(result) {
			},
			success: function(data, textStatus) {
				if (data.error) {
					alert(data.error);
					if (data.value) {
						$(thisObj).closest('td').find('input[name=quantity]').val(data.value);
					}
				} else {
					$('.cItemCount').html(data.itemCount);
					$('.cTotal').html(data.total);
					$('.subtotal', $(thisObj).closest('tr')).html(data.subtotal);
					$('#cart .total').html(data.total);
				}
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				alert('Error: '+textStatus);
			}
		});
	});
	
	$('#frmLogin').submit(function(index, domEle) {
		
		var thisObj = this;
		
		$.ajax({
			type: "POST",
			data: "func=loginUser&"+$(this).serialize(),
			cache: false,
			dataType: "json",
			beforeSend: function(result) {
				$(thisObj).find('.submit').val('Please Wait...').attr('disabled', 'disabled');
				$(thisObj).find('.frmErr').remove();
			},
			success: function(data, textStatus) {
				if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('tr').find('td:last').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						alert(data.msg);
					}
					$('.frmErr', thisObj).fadeIn('slow');
					rebind();
					$(thisObj).find('.submit').attr('disabled', '');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$(thisObj).find('.submit').val('Try Again').attr('disabled', '');
					
				} else if (data.success) {
					
					if (data.location) {
						window.location.href = data.location;
					} else {
						window.location.reload();
					}
					
				} else {
					
					alert(textStatus);
					
				}
			}
		});
		
        return false;
		
	});
	
	$('#frmForgot').submit(function(index, domEle) {
		
		var thisObj = this;
		
		$.ajax({
			type: "POST",
			data: "func=forgotPassword&"+$(this).serialize(),
			cache: false,
			dataType: "json",
			beforeSend: function(result) {
				$(thisObj).find('.submit').val('Please Wait...').attr('disabled', 'disabled');
				$(thisObj).find('.frmErr').remove();
			},
			success: function(data, textStatus) {
				if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('tr').find('td:last').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						alert(data.msg);
					}
					$('.frmErr', thisObj).fadeIn('slow');
					rebind();
					$(thisObj).find('.submit').attr('disabled', '');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$(thisObj).find('.submit').val('Try Again').attr('disabled', '');
					
				} else if (data.success) {
					
					$(thisObj).closest('#divForgot').hide().html(data.success).fadeIn('slow');
					
				} else {
					
					alert(textStatus);
					
				}
			}
		});
		
        return false;
		
	});
	
	$('#frmMember').submit(function(index, domEle) {
		
		var thisObj = this;
		
		$.ajax({
			type: "POST",
			data: "func=doProfile&"+$(this).serialize(),
			cache: false,
			dataType: "json",
			beforeSend: function(result) {
				$(thisObj).find('.submit')
					.attr('orig', $(thisObj).find('.submit').val())
					.val('Please Wait...')
					.attr('disabled', 'disabled');
				$('#errorBar', thisObj).slideUp('fast');
				$(thisObj).find('.frmErr').remove();
			},
			success: function(data, textStatus) {
				if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('tr').find('td:last').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						$('#errorBar', thisObj).html(data.msg).slideDown('fast');
					}
					$('.frmErr').fadeIn('slow');
					rebind();
					$(thisObj).find('.submit').val($(thisObj).find('.submit').attr('orig')).attr('disabled', '');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$(thisObj).find('.submit').val('Try Again').attr('disabled', '');
					
				} else if (data.success) {
					
					$(thisObj).find('.submit').val($(thisObj).find('.submit').attr('orig')).attr('disabled', '');
					$(thisObj).closest('.bodyText').hide().html(data.success).fadeIn('slow');
					
					if (data.location) {
						window.location.href = data.location;
					} else if (data.reload) {
						setTimeout('window.location.reload()', 4000);
					}
					
				} else {
					
					alert(textStatus);
					
				}
			}
		});
		
        return false;
		
	});
	
	$('#frmContact').submit(function(index, domEle) {
		
		var thisObj = this;
		
		$.ajax({
			type: "POST",
			data: "func=doContact&"+$(this).serialize(),
			cache: false,
			dataType: "json",
			beforeSend: function(result) {
				$(thisObj).find('.submit')
					.attr('orig', $(thisObj).find('.submit').val())
					.val('Please Wait...')
					.attr('disabled', 'disabled');
				$('#errorBar', thisObj).slideUp('fast');
				$(thisObj).find('.frmErr').remove();
			},
			success: function(data, textStatus) {
				if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('tr').find('td:last').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						$('#errorBar', thisObj).html(data.msg).slideDown('fast');
					}
					$('.frmErr').fadeIn('slow');
					rebind();
					$(thisObj).find('.submit').val($(thisObj).find('.submit').attr('orig')).attr('disabled', '');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$(thisObj).find('.submit').val('Try Again').attr('disabled', '');
					
				} else if (data.success) {
					
					$(thisObj).find('.submit').val($(thisObj).find('.submit').attr('orig')).attr('disabled', '');
					$(thisObj).closest('.bodyText').hide().html(data.success).fadeIn('slow');
					
					if (data.location) {
						window.location.href = data.location;
					} else if (data.reload) {
						setTimeout('window.location.reload()', 4000);
					}
					
				} else {
					
					alert(textStatus);
					
				}
			}
		});
		
        return false;
		
	});
	
	$('#frmCheckout').submit(function(index, domEle) {
		
		var thisObj = this;
		
		$.ajax({
			type: "POST",
			data: "func=doCheckout&"+$(this).serialize(),
			cache: false,
			dataType: "json",
			beforeSend: function(result) {
				$('#paymentBar', thisObj).slideUp('fast');
				$('#submitBar', thisObj).slideUp('fast');
				$('#loadingBar', thisObj).slideDown('fast');
				$('#errorBar', thisObj).slideUp('fast');
				$(thisObj).find('.frmErr').remove();
			},
			success: function(data, textStatus) {
				if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('tr').find('td:last').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						$('#errorBar', thisObj).html(data.msg).slideDown('fast');
					}
					$('.frmErr').fadeIn('slow');
					
					rebind();
					
					$('#loadingBar', thisObj).slideUp('fast');
					$('#submitBar', thisObj).slideDown('fast');
					$('#paymentBar', thisObj).slideDown('fast');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$('#loadingBar', thisObj).slideUp('fast');
					$('#submitBar', thisObj).slideDown('fast');
					$('#paymentBar', thisObj).slideDown('fast');
					
				} else if (data.success) {
					
					$(thisObj).closest('.bodyText').hide().html(data.success).fadeIn('slow');
					
					if (data.location) {
						window.location.href = data.location;
					} else if (data.reload) {
						setTimeout('window.location.reload()', 4000);
					}
					
				} else {
					
					alert(textStatus);
					
				}
			}
		});
		
        return false;
		
	});
	
});


function rebind() {
	
	$('.defuscate').defuscate();

	if ($('#colTwo').height()) {
		if ($('#colOne').height() < $('#colTwo').height()) {
			$('#colOne').css({'height':($('#colTwo').height())});
		}
	}
	
	$('.suggestion, #featuredProducts .item, .sizeQty, .frmErr').qtip({
		content: {
			text: false // Use each elements title attribute
		},
		show: { delay: 100 },
		position: {
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			}
		},
		style: { 
			width: 150,
			fontSize: '10pt',
			lineHeight: '12pt',
			padding: 5,
			background: '#ffcc00',
			color: '#000',
			textAlign: 'center',
			border: {
				width: 3,
				color: '#ffcc00'
			},
			tip: 'bottomMiddle',
			name: 'dark' // Inherit the rest of the attributes from the preset dark style
		}
	});
	
	$('.qTip').each(function()
	{
		$(this).qtip({
			content: {
				text: '<img src="images/loading.gif" alt="Loading..." />',
				url: 'qtip.php?load='+$(this).attr('load')
			},
			show: { delay: 100 },
			position: {
				corner: {
					target: 'topMiddle',
					tooltip: 'bottomMiddle'
				}
			},
			style: { 
				fontSize: '10pt',
				lineHeight: '12pt',
				padding: 5,
				background: '#ffcc00',
				color: '#000',
				textAlign: 'center',
				border: {
					width: 3,
					color: '#ffcc00'
				},
				tip: 'bottomMiddle',
				name: 'dark'
			}
		})
	});

}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function doFlashPos(flashDiv) {
	var flashPos = $('#colOne').offset();
	var flashLeft = flashPos.left+$('#colOne').width();
	var flashWidth = $(flashDiv).width();
	var screenWidth = $(window).width();
	var flashDiff = screenWidth - flashWidth - flashLeft;
	var newWidth = flashDiff + flashWidth;
	$(flashDiv).css('width',newWidth+'px');
}

function preloadBG(img) {
	
	$('#preloader').show();
	
	var newLoad = $("<img />").addClass('hidden').attr('src',$('#preloader').attr('src'));
	$('#preloader').append(newLoad);
	
	$('#preloader img')
		.load(function() {
			$('body').css('backgroundImage', 'url('+$(this).attr('src')+')');
			$('#preloader img').remove();
			$('#preloader').fadeOut('slow');
		})
		.error(function () {
			alert('Error loading image. Try reloading this page.');
		});
}

function flashRequest(func, obj) {
	
	//alert(func);
	
	//var obj = new Array(); eval("obj="+obj);
	
	switch (func) {
		
		case 'setBackground':
			if (obj.img) {
				$('#over-layer').css('backgroundImage', 'url('+obj.img+')');
			} else if (obj.colour) {
				$('#preloader').css({'backgroundImage': 'none', 'backgroundColor': obj.colour}).fadeIn('fast');
			} else {
				$('#preloader').fadeOut("fast", function(){$(this).css({'backgroundImage': 'url(images/loading.gif)', 'backgroundColor': 'none'});});
			}
			break;
		
		case 'divHeight':
			$('#flash-layer').css('height', obj+'px');
			break;
		
		case 'divExpand':
			$('#colTwo, #colThree').fadeOut('fast');
			$('#preloader').fadeIn('slow');
			$('#flash-layer').css('height', siteHeight+'px');
			break;
		
		case 'divContract':
			$('#preloader').fadeOut('slow');
			$('#colTwo, #colThree').fadeIn('fast');
			$('#flash-layer').css('height', '175px');
			break;
		
		case 'collection':
			//return selCollection;
			thisMovie("collection").flashRequest(selCollection);
			break;
			
		case 'debug':
			
			if (obj) {
				var echo = '';
				for (prop in obj) {
					if ('object' == typeof(obj[prop])) {
						for (subObj in obj[prop]) {
							echo += subObj + ": " + obj[prop][subObj] + "\n";
						}
					} else {
						echo += prop + ": " + obj[prop] + "\n";
					}
				}
				alert(echo);
			} else {
				alert('No Object!');
			}
			break;
			
		default:
			alert('Not a valid flash request!');
	}
	
	//sendToActionScript(func);
}
function thisMovie(movieName) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
		 return window[movieName];
	 } else {
		 return document[movieName];
	 }
 }
 function sendToActionScript(value) {
	 thisMovie("collection").sendToActionScript(value);
 }
 

/* Email Defuscator */
(function($){
	jQuery.fn.defuscate = function( settings ) {
		settings = jQuery.extend({
			link: true,
			find: /\b([A-Z0-9._%-]+)\([^)]+\)((?:[A-Z0-9-]+\.)+[A-Z]{2,6})\b/gi,
			replace: '$1@$2'
		}, settings);
		return this.each(function() {
			if ( $(this).is('a[@href]') ) {
				$(this).attr('href', $(this).attr('href').replace(settings.find, settings.replace));
				var is_link = true;
			}
			$(this).html($(this).html().replace(settings.find, (settings.link && !is_link ? '<a href="mailto:' + settings.replace + '">' + settings.replace + '</a>' : settings.replace)));
		});
	};
})(jQuery);


/* radio replacement plugin */
(function($) {
	$.fn.inputReplace = function(e) {
		switch (e) {
			case 'radio':
				
				$(" + label", this)
					.each( function(){
						$(this).addClass($(this).prev().attr('class')+"_label").attr('title',$(this).attr('title'));
						if ( $(this).prev()[0].disabled ) {
							if ( $(this).prev()[0].checked ) {
								$(this).addClass("checked_disabled");
							} else {
								$(this).addClass("disabled");
							}
						} else if ( $(this).prev()[0].checked ) {
							$(this).addClass("checked");
						}
					})
					.hover( 
						function() { $(this).addClass("over"); },
						function() { $(this).removeClass("over"); }
					)
					.click( function() {
						if ( !$(this).prev()[0].disabled ) {
							$("."+$(this).prev().attr('class')+"_label").removeClass("checked").removeClass("checked_disabled");
							$(this).addClass("checked");
							var resetVal = ($(this).prev().attr('maxvalue'));
							$('.quantityArea input[name=quantity]').val(1);
							$('#'+$(this).attr('for')).attr('checked','checked');
							//$("input['"+$(this).prev().attr('name')+"']").checked = '';
							//$(this).prev()[0].checked = !$(this).prev()[0].checked;
						}
					})
					.prev().hide();
				break;
				
			case 'incrementer':
				
				//$(this).before('<a href="#" class="minus button">-</a>');
				//$(this).after('<a href="#" class="plus button">+</a>');
				$(this).after('<div class="arrows"><div><a href="#" class="plus"><img src="images/up_arrow.gif" /></a></div><div><a href="#" class="minus"><img src="images/down_arrow.gif" /></a></div></div>');
				
				$('.plus, .minus').click(function() {
					
					var quantity = $(this).closest('.quantityArea').find('input[name=quantity]').val();
					var quantityMax = ($('input[name=size]:checked').attr('maxvalue')) ? parseInt($('input[name=size]:checked').attr('maxvalue')) : 1;
					
					if ($(this).hasClass('plus') && quantity < quantityMax) {
						quantity++;
					} else if ($(this).hasClass('minus') && quantity > 1) {
						quantity--;
					}
					$(this).closest('.quantityArea').find('input[name=quantity]').val(quantity);
					return false;
				});
				break;
				
			case 'cartQty':
				
				$(this).after('<div class="arrows"><div><a href="#" class="up"><img src="images/up_arrow.gif" /></a></div><div><a href="#" class="down"><img src="images/down_arrow.gif" /></a></div></div>');
				
				$('.up, .down').click(function() {
					
					var thisObj = this;				   
					
					var quantity = $(thisObj).closest('td').find('input[name=quantity]').val();
					var quantityMax = ($('input[name=size]:checked').attr('maxvalue')) ? parseInt($('input[name=size]:checked').attr('maxvalue')) : 99;
					
					if ($(thisObj).hasClass('up') && quantity < quantityMax) {
						quantity++;
					} else if ($(thisObj).hasClass('down') && quantity > 1) {
						quantity--;
					}
					$(thisObj).closest('td').find('input[name=quantity]').val(quantity).trigger('change');
					return false;
					
				});
				break;
		}
	}
})(jQuery);


/**
 *  jquery.popupt
 *  (c) 2008 Semooh (http://semooh.jp/)
 *
 *  Dual licensed under the MIT (MIT-LICENSE.txt)
 *  and GPL (GPL-LICENSE.txt) licenses.
 *
 **/
(function($){
	$.fn.extend({
		imghover: function(opt){
			return this.each(function() {
        opt = $.extend({
            prefix: '',
            suffix: '_o',
            src: '',
            btnOnly: true,
            fade: false,
            fadeSpeed: 500
          }, opt || {});

        var node = $(this);
				if(!node.is('img')&&!node.is(':image')){
          var sel = 'img,:image';
          if (opt.btnOnly) sel = 'a '+sel;
          node.find(sel).imghover(opt);
          return;
        }

        var orgImg = node.attr('src');

        var hoverImg;
        if(opt.src){
          hoverImg = opt.src;
        }else{
          hoverImg = orgImg;
          if(opt.prefix){
            var pos = hoverImg.lastIndexOf('/');
            if(pos>0){
              hoverImg = hoverImg.substr(0,pos-1)+opt.prefix+hoverImg.substr(pos-1);
            }else{
              hoverImg = opt.prefix+hoverImg;
            }
          }
          if(opt.suffix){
            var pos = hoverImg.lastIndexOf('.');
            if(pos>0){
              hoverImg = hoverImg.substr(0,pos)+opt.suffix+hoverImg.substr(pos);
            }else{
              hoverImg = hoverImg+opt.suffix;
            }
          }
        }

        if(opt.fade){
          var offset = node.offset();
          var hover = node.clone(true);
          hover.attr('src', hoverImg);
          hover.css({
            position: 'absolute',
            left: offset.left,
            top: offset.top,
            zIndex: 1000
          }).hide().insertAfter(node);
          node.mouseover(
            function(){
              var offset=node.offset();
              hover.css({left: offset.left, top: offset.top});
              hover.fadeIn(opt.fadeSpeed);
              node.fadeOut(opt.fadeSpeed,function(){node.show()});
            }
          );
          hover.mouseout(
            function(){
              node.fadeIn(opt.fadeSpeed);
              hover.fadeOut(opt.fadeSpeed);
            }
          );
        }else{
          node.hover(
            function(){node.attr('src', hoverImg)},
            function(){node.attr('src', orgImg)}
          );
        }
			});
		}
	});
})(jQuery);
