// JavaScript Document

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

$(document).ready(function(){
	
	ddsmoothmenu.init({
		mainmenuid: "main_nav",
		orientation: 'h',
		classname: 'ddsmoothmenu',
		contentsource: "markup"
	});
	
	$.ajaxSetup({
		url: "_konstrukt/ajax.gateway.php",
		global: false
	});

	rebind();
	
	$('.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');

	// HIDE ALL SCROLL BARS
	$('.scroll_pane').css("overflow-x","hidden");
	$('.scroll_pane').css("overflow-y","hidden");
	$('li:first', '#poster_scroll').addClass('first').addClass('current');
	$('li:last', '#poster_scroll').addClass('last');
    
	$('.arrow_right').live('click', function() {
		if (!$('li.current', '#poster_scroll').hasClass('last')) {
			$('#poster_scroll').stop().scrollTo( $('li.current','#poster_scroll').removeClass('current').next().addClass('current'), 500 );
		}
		$(this).blur();
		return false;
	});

	$('.arrow_left').live('click', function() {
		if (!$('li.current', '#poster_scroll').hasClass('first')) {
			$('#poster_scroll').stop().scrollTo( $('li.current','#poster_scroll').removeClass('current').prev().addClass('current'), 500 );
		}
		$(this).blur();
		return false;
	});
	
	$('#cat_thumbs .thumb').click(function() {
		$('li', '#poster_scroll').removeClass('current');
		$('#'+$(this).attr('rel')).addClass('current');
		$('#poster_scroll').stop().scrollTo( $('.current','#poster_scroll'), 500 );
		$(this).blur();
		return false;
	});

	
	$(".jqzoom").jqzoom({
		title: false,
	    zoomWidth: 476,
	    zoomHeight: 595,
		position: "right",
        zoomType: 'standard',  
        lens:true,  
        xOffset:32,  
        yOffset:0
	});
	
	$(".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);
		return false;
	});
	
	$('.forgot').click(function() {		
		if ($('#divLogin').is(':visible')) {
			$('#divLogin').hide();
			$('#divForgot').fadeIn('fast');
		} else {
			$('#divForgot').hide();
			$('#divLogin').fadeIn('fast');
		}
		return false;
	});
	
	$('.imageOptions a').click(function() {
		$('.image a').attr('href', $(this).attr('image'));
		$('.image img').hide().attr('src', $(this).attr('href')).fadeIn();
		$(this).blur();
        return false;
	});
	
	$('#storeStates a').live('click', function() {
		$('a', '#storeStates').removeClass('selected');
		$('li', '#markers').hide('fast');
		$('.'+$(this).attr('rel'), '#markers').show('fast');
		$(this).addClass('selected').blur();
        return false;
	});
	
	$('#same_shipping').click(function(index, domEle) {
		
		var thisObj = this;
		
		if ($(thisObj).is(':checked')) {
			$('#shipping_address').hide();
			/*$(".clone").each( function(){
				$('#'+$(this).attr('id')+'_shipping').val($(this).val());
			});*/
			$(".clone").each( function(){
				$('#'+$(this).attr('id')+'_shipping').val('');
			});
		} else {
			$('#shipping_address').show();
		}
		
	});
	
	
	$('#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) {
				$('.resultBar, .errorBar, .frmErr').remove();
			},
			success: function(data, textStatus) {
				if (data.error) {
					$('.row:first', thisObj).prepend('<div class="errorBar"></div>');
					$('.errorBar', thisObj).html(data.error).slideDown('fast');
				} else {
					$('.cItemCount').html(data.itemCount);
					$('.cTotal').html('$'+data.subtotal);
					
					$('.row:first', thisObj).prepend('<div class="resultBar"></div>');
					$('.resultBar', thisObj).html(data.html).slideDown('fast');

					setTimeout("$('.resultBar').slideUp('fast')", 3000);
				}
			},
			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);
			}
		});
	});
	
	$('#colwash').change(function() {
		
		var thisObj = this;

		window.location.href = $(thisObj).val();
		
	});
	
	$('#frmLogin').submit(function(index, domEle) {
		
		var thisObj = this;
		
		$.ajax({
			type: "POST",
			data: "func=loginUser&"+$(this).serialize(),
			cache: false,
			dataType: "json",
			beforeSend: function(result) {
				$('.submit', thisObj).buttonStatus('busy');
				$('.errorBar, .frmErr').remove();
			},
			success: function(data, textStatus) {
				if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('.row').find('.label').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						$('.row:first', thisObj).prepend('<div class="errorBar"></div>');
						$('.errorBar', thisObj).html(data.msg).slideDown('fast');
					}
					$('.frmErr', thisObj).fadeIn('slow');
					rebind();
					$('.submit', thisObj).buttonStatus('reset');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$('.submit', thisObj).buttonStatus('reset');
					
				} 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) {
				$('.submit', thisObj).buttonStatus('busy');
				$('.errorBar, .frmErr').remove();
			},
			success: function(data, textStatus) {
				if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('.row').find('.label').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						$('.row:first', thisObj).prepend('<div class="errorBar"></div>');
						$('.errorBar', thisObj).html(data.msg).slideDown('fast');
					}
					$('.frmErr', thisObj).fadeIn('slow');
					rebind();
					$('.submit', thisObj).buttonStatus('reset');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$('.submit', thisObj).buttonStatus('reset');
					
				} 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) {
				$('.submit', thisObj).buttonStatus('busy');
				$('.errorBar, .frmErr, .resultBar').remove();
			},
			success: function(data, textStatus) {
				if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('.row').find('.label').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						$('.row:first', thisObj).prepend('<div class="errorBar"></div>');
						$('.errorBar', thisObj).html(data.msg).slideDown('fast');
					}
					$('.frmErr').fadeIn('slow');
					rebind();
					$('.submit', thisObj).buttonStatus('reset');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$('.submit', thisObj).buttonStatus('reset');
					
				} else if (data.success) {

					$('.submit', thisObj).buttonStatus('reset');
					$('.row:first', thisObj).prepend('<div class="resultBar"></div>');
					$('.resultBar', thisObj).html(data.success).slideDown('fast');
					//setTimeout("$('.resultBar').slideUp('fast')", 5000);
					setTimeout('window.location.reload()', 4000);
					
				} else {
					
					alert(textStatus);
					
				}
			}
		});
		
        return false;
		
	});
	
	$('#frmSubscribe').submit(function(index, domEle) {
		
		var thisObj = this;
		
		$.ajax({
			type: "POST",
			data: "func=doSubscribe&"+$(this).serialize(),
			cache: false,
			dataType: "json",
			beforeSend: function(result) {
				//$('.form_elements', thisObj).hide();
				//$('.message', thisObj).fadeIn();
				$('.submit', thisObj).buttonStatus('busy');
			},
			success: function(data, textStatus) {
				 if (data.success) {

					$('.form_elements', thisObj).hide();
					$('.message', thisObj).html(data.success).fadeIn();
					$('.submit', thisObj).buttonStatus('reset');
						
				} else if (data.msg) {
					
					$('.form_elements', thisObj).hide();
					$('.message', thisObj).html(data.msg).fadeIn();
					$('.submit', thisObj).buttonStatus('reset');
					
					setTimeout("$('.message', '#frmSubscribe').hide(); $('.form_elements', '#frmSubscribe').fadeIn();", 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) {
				$('.submit', thisObj).buttonStatus('busy');
				$('.errorBar, .frmErr').remove();
			},
			success: function(data, textStatus) {
				if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('.row').find('.label').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						$('.row:first', thisObj).prepend('<div class="errorBar"></div>');
						$('.errorBar', thisObj).html(data.msg).slideDown('fast');
					}
					$('.frmErr').fadeIn('slow');
					rebind();
					$('.submit', thisObj).buttonStatus('reset');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$('.submit', thisObj).buttonStatus('reset');
					
				} 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;
		var thisObj = $(thisObj).closest('.payment_form');

		$.ajax({
			type: "POST",
			data: "func=doCheckout&"+$(this).serialize(),
			cache: false,
			dataType: "json",
			beforeSend: function(result) {
				$('#paymentBar').slideUp('fast');
				$('#submitBar').slideUp('fast');
				$('#loadingBar').slideDown('fast');
				$('.errorBar, .frmErr').remove();
				$('#checkout_submit').buttonStatus('busy');
			},
			success: function(data, textStatus) {

				if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('tr').find('label:first').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						$('#paymentBar').prepend('<div class="errorBar"></div>');
						$('#paymentBar .errorBar').html(data.msg).slideDown('fast');
					}
					$('.frmErr').fadeIn('slow');
					
					rebind();
					
					$('#loadingBar').slideUp('fast');
					$('#submitBar').slideDown('fast');
					$('#paymentBar').slideDown('fast');
					$('#checkout_submit').buttonStatus('fail');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$('#loadingBar').slideUp('fast');
					$('#submitBar').slideDown('fast');
					$('#paymentBar').slideDown('fast');
					$('#checkout_submit').buttonStatus('fail');
					
				} else if (data.success) {
					
					$(thisObj).closest('.full_column.form').hide().html(data.msg).fadeIn('slow');
					
					if (data.location) {
						window.location.href = data.location;
					} else if (data.reload) {
						setTimeout('window.location.reload()', 4000);
					}
					
				} else {
					
					alert(textStatus);
					
				}
			}
		});
		
        return false;
		
	});

	$('.payment_method_btn').click(function() {

		var thisObj = this;

        $('.payment_form').hide();

		//$('#colTwo').css({'height':'auto'});
        
        $('#'+$(thisObj).attr('rel')).slideDown('fast');

        $('#checkout_submit').attr('target', $(thisObj).attr('rel'));

        $('.payment_method_btn').removeClass('selected');
        $(thisObj).addClass('selected').blur();

        return false;

	});

	$('#checkout_submit').click(function() {

		var thisObj = this;
		var target = $(thisObj).attr('target'); // Set which form to target for submission
        var delivery_comment = $('textarea', '#delivery_comments').val(); // Set delivery comment variable
        
        if (target == 'paypalBar') {
            
            $.ajax({
                type: "POST",
                data: "func=doPaypalCheckout&delComment="+delivery_comment+"&"+$(this).serialize(),
                cache: false,
                dataType: "json",
                beforeSend: function(result) {
                    $('#submitBar').slideUp('fast');
                    $('#loadingBar').slideDown('fast');
    				$('.errorBar, .frmErr').remove();
                },
                success: function(data, textStatus) {

                    if (data.errors) {
                        for (var i in data.errors) {
    						$('#'+i, thisObj).closest('.row').find('.label').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
                        }
                        if (data.msg) {
    						$('.row:first', thisObj).prepend('<div class="errorBar"></div>');
    						$('.errorBar', thisObj).html(data.msg).slideDown('fast');
                        }
                        $('.frmErr').fadeIn('slow');

                        rebind();

                        $('#loadingBar').slideUp('fast');
                        $('#submitBar').slideDown('fast');
    					$('#checkout_submit').buttonStatus('fail');

                    } else if (data.alertMsg) {

                        alert(data.alertMsg);
                        $('#loadingBar').slideUp('fast');
                        $('#submitBar').slideDown('fast');
    					$('#checkout_submit').buttonStatus('fail');

                    } else if (data.success) {

                        // set order_id
                        $('input[name=invoice]', '#'+target+' form').val(data.order_id);

                        // set trxn_id
                        $('input[name=custom]', '#'+target+' form').val(data.trxn_id);

                        $('input[name=verify_sign]', '#'+target+' form').val(data.verify_sign);

                        // Submit to PayPal
                        $('form', '#'+target).submit();

                    } else {

                        alert(textStatus);

                    }
                }
            });

        } else {

            // Set delivery comment
            $('input[name=delComment]', '#'+target+' form').val(delivery_comment);

            // Submit to payment gateway
            $('form', '#'+target).submit();
        }

        return false;

	});
	
	$('#video_list ul li a').live('click', function() {
		
		thisObj = this;
		
		$('#video_frame').attr('src',$(this).attr('href'));
		
		$.scrollTo('#content', 500);
		
		$('#video_list .selected').removeClass('selected');
		$(this).closest('li').addClass('selected');
		$('#video_desc').html($('.description a',$(thisObj).closest('li')).html());
		$(this).blur();
		return false;
	});
	
});


function rebind() {
	
	$('.defuscate').defuscate();
	
	$("#sizes").qtip({
		   content: {
		      url: 'sizes.php',
		      data: { min: 'true' },
		      method: 'get'
		   },
		   /*style: { 
			      border: {
			         width: 3,
			         radius: 8,
			         color: '#6699CC'
			      },
			      width: 500
			}*/
		   style: { 
			      name: 'dark', // Inherit from preset style
			      textAlign: 'center',
				  width: 475
			   },
			position: {
				corner: {
					target: 'topMiddle',
					tooltip: 'bottomMiddle'
				}
			}
		});
	
	$('.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: '#aaeeff',
			color: '#000',
			textAlign: 'center',
			border: {
				width: 3,
				color: '#aaeeff'
			},
			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: '#aaeeff',
				color: '#000',
				textAlign: 'center',
				border: {
					width: 3,
					color: '#aaeeff'
				},
				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 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.');
		});
}

/* 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'));
							$('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="up"><img src="images/up_arrow.gif" /></a>');
				//$(this).after('<a href="#" class="down"><img src="images/down_arrow.gif" /></a>');
				
				$(this).before('<a href="#" class="minus button">-</a>');
				$(this).after('<a href="#" class="plus button">+</a>');
				
				$('.plus, .minus').click(function() {
					
					var quantity = $(this).closest('.input').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('.input').find('input[name=quantity]').val(quantity);
					return false;
				});
				break;
				
			case 'cartQty':
				
				$(this).before('<a href="#" class="down button">-</a>');
				$(this).after('<a href="#" class="up button">+</a>');
				
				$('.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);

//button processor
(function($){
	jQuery.fn.buttonStatus = function( mode ) {
		if ( mode == 'busy' ) {
			$(this).data('original', $(this).val());
			$(this)
			.val('Please Wait...')
			.addClass('button_load')
			.attr("disabled", true);
		} else if ( mode == 'done' ) {
			$(this)
			.val($(this).data('original'))
			.removeClass('button_load')
			.addClass('button_done')
			.removeAttr("disabled");
		} else if ( mode == 'fail' ) {
			$(this)
			.val($(this).data('original'))
			.removeClass('button_load')
			.removeClass('button_done')
			.addClass('button_fail')
			.removeAttr("disabled");
		} else if ( mode == 'reset' ) {
			$(this)
			.val($(this).data('original'))
			.removeClass('button_fail')
			.removeClass('button_load')
			.removeClass('button_done')
			.removeAttr("disabled");
		}
	};
})(jQuery);

