/*
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate$
 * $Rev$
 */
jQuery.fn._height=jQuery.fn.height;jQuery.fn._width=jQuery.fn.width;jQuery.fn.height=function(){if(this[0]==window)return self.innerHeight||jQuery.boxModel&&document.documentElement.clientHeight||document.body.clientHeight;if(this[0]==document)return Math.max(document.body.scrollHeight,document.body.offsetHeight);return this._height(arguments[0])};jQuery.fn.width=function(){if(this[0]==window)return self.innerWidth||jQuery.boxModel&&document.documentElement.clientWidth||document.body.clientWidth;if(this[0]==document)return Math.max(document.body.scrollWidth,document.body.offsetWidth);return this._width(arguments[0])};jQuery.fn.innerHeight=function(){return this[0]==window||this[0]==document?this.height():this.css('display')!='none'?this[0].offsetHeight-(parseInt(this.css("borderTopWidth"))||0)-(parseInt(this.css("borderBottomWidth"))||0):this.height()+(parseInt(this.css("paddingTop"))||0)+(parseInt(this.css("paddingBottom"))||0)};jQuery.fn.innerWidth=function(){return this[0]==window||this[0]==document?this.width():this.css('display')!='none'?this[0].offsetWidth-(parseInt(this.css("borderLeftWidth"))||0)-(parseInt(this.css("borderRightWidth"))||0):this.height()+(parseInt(this.css("paddingLeft"))||0)+(parseInt(this.css("paddingRight"))||0)};jQuery.fn.outerHeight=function(){return this[0]==window||this[0]==document?this.height():this.css('display')!='none'?this[0].offsetHeight:this.height()+(parseInt(this.css("borderTopWidth"))||0)+(parseInt(this.css("borderBottomWidth"))||0)+(parseInt(this.css("paddingTop"))||0)+(parseInt(this.css("paddingBottom"))||0)};jQuery.fn.outerWidth=function(){return this[0]==window||this[0]==document?this.width():this.css('display')!='none'?this[0].offsetWidth:this.height()+(parseInt(this.css("borderLeftWidth"))||0)+(parseInt(this.css("borderRightWidth"))||0)+(parseInt(this.css("paddingLeft"))||0)+(parseInt(this.css("paddingRight"))||0)};jQuery.fn.scrollLeft=function(){if(this[0]==window||this[0]==document)return self.pageXOffset||jQuery.boxModel&&document.documentElement.scrollLeft||document.body.scrollLeft;return this[0].scrollLeft};jQuery.fn.scrollTop=function(){if(this[0]==window||this[0]==document)return self.pageYOffset||jQuery.boxModel&&document.documentElement.scrollTop||document.body.scrollTop;return this[0].scrollTop};jQuery.fn.offset=function(options,returnObject){var x=0,y=0,elem=this[0],parent=this[0],absparent=false,relparent=false,op,sl=0,st=0,options=jQuery.extend({margin:true,border:true,padding:false,scroll:true},options||{});do{x+=parent.offsetLeft||0;y+=parent.offsetTop||0;if(jQuery.browser.mozilla||jQuery.browser.msie){var bt=parseInt(jQuery.css(parent,'borderTopWidth'))||0;var bl=parseInt(jQuery.css(parent,'borderLeftWidth'))||0;x+=bl;y+=bt;if(jQuery.browser.mozilla&&parent!=elem&&jQuery.css(parent,'overflow')!='visible'){x+=bl;y+=bt}if(jQuery.css(parent,'position')=='absolute')absparent=true;if(jQuery.css(parent,'position')=='relative')relparent=true}if(options.scroll){op=parent.offsetParent;do{sl+=parent.scrollLeft||0;st+=parent.scrollTop||0;parent=parent.parentNode;if(jQuery.browser.mozilla&&parent!=elem&&parent!=op&&jQuery.css(parent,'overflow')!='visible'){x+=parseInt(jQuery.css(parent,'borderLeftWidth'))||0;y+=parseInt(jQuery.css(parent,'borderTopWidth'))||0}}while(op&&parent!=op)}else parent=parent.offsetParent;if(parent&&(parent.tagName.toLowerCase()=='body'||parent.tagName.toLowerCase()=='html')){if((jQuery.browser.safari||(jQuery.browser.msie&&jQuery.boxModel))&&jQuery.css(elem,'position')!='absolute'){x+=parseInt(jQuery.css(parent,'marginLeft'))||0;y+=parseInt(jQuery.css(parent,'marginTop'))||0}if((jQuery.browser.mozilla&&!absparent)||(jQuery.browser.msie&&jQuery.css(elem,'position')=='static'&&(!relparent||!absparent))){x+=parseInt(jQuery.css(parent,'borderLeftWidth'))||0;y+=parseInt(jQuery.css(parent,'borderTopWidth'))||0}break}}while(parent);if(!options.margin){x-=parseInt(jQuery.css(elem,'marginLeft'))||0;y-=parseInt(jQuery.css(elem,'marginTop'))||0}if(options.border&&(jQuery.browser.safari||jQuery.browser.opera)){x+=parseInt(jQuery.css(elem,'borderLeftWidth'))||0;y+=parseInt(jQuery.css(elem,'borderTopWidth'))||0}else if(!options.border&&!(jQuery.browser.safari||jQuery.browser.opera)){x-=parseInt(jQuery.css(elem,'borderLeftWidth'))||0;y-=parseInt(jQuery.css(elem,'borderTopWidth'))||0}if(options.padding){x+=parseInt(jQuery.css(elem,'paddingLeft'))||0;y+=parseInt(jQuery.css(elem,'paddingTop'))||0}if(options.scroll&&jQuery.browser.opera&&jQuery.css(elem,'display')=='inline'){sl-=elem.scrollLeft||0;st-=elem.scrollTop||0}var returnValue=options.scroll?{top:y-st,left:x-sl,scrollTop:st,scrollLeft:sl}:{top:y,left:x};if(returnObject){jQuery.extend(returnObject,returnValue);return this}else{return returnValue}};

(function($){$.fn.jqm=function(p){var o={zIndex:3000,overlay:50,overlayClass:'jqmOverlay',closeClass:'jqmClose',trigger:'.jqModal',ajax:false,target:false,modal:false,toTop:false,onShow:false,onHide:false,onLoad:false};return this.each(function(){if(this._jqm)return;s++;this._jqm=s;H[s]={c:$.extend(o,p),a:false,w:$(this).addClass('jqmID'+s),s:s};o.trigger&&$(this).jqmAddTrigger(o.trigger)})};$.fn.jqmAddClose=function(e){return HS(this,e,'jqmHide')};$.fn.jqmAddTrigger=function(e){return HS(this,e,'jqmShow')};$.fn.jqmShow=function(t){return this.each(function(){!H[this._jqm].a&&$.jqm.open(this._jqm,t)})};$.fn.jqmHide=function(t){return this.each(function(){H[this._jqm].a&&$.jqm.close(this._jqm,t)})};$.jqm={hash:{},open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=/^\d+$/.test(h.w.css('z-index'))&&h.w.css('z-index')||c.zIndex,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100,display:'none'});h.t=t;h.a=true;h.w.css('z-index',z);if(c.modal){!A[0]&&F('bind');A.push(s);o.css('cursor','wait')}else if(c.overlay>0)h.w.jqmAddClose(o);else o=false;h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):false;if(c.ajax){var r=c.target||h.w,u=c.ajax,r=(typeof r=='string')?$(r,h.w):$(r),u=(u.substr(0,1)=='@')?$(t).attr(u.substring(1)):u;r.load(u,function(){c.onLoad&&c.onLoad.call(this,h);cc&&h.w.jqmAddClose($(cc,h.w));O(h)})}else cc&&h.w.jqmAddClose($(cc,h.w));c.toTop&&h.o&&h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);c.onShow&&c.onShow(h);h.w.show();h.w.css({top:($(window).myHeight()/2)+$(window).scrollTop()-(h.w.height()/2)});O(h);if($.browser.msie&&o){o=o.css({height:$(document).scrollTop()+$(document).myHeight(),position:'absolute',top:'0',left:'0',display:'block'})}else{o.css({display:'block'})}return false},close:function(s){var h=H[s];h.a=false;if(h.c.modal){A.pop();!A[0]&&F('unbind')}h.c.toTop&&h.o&&$('#jqmP'+h.w[0]._jqm).after(h.w).remove();if(h.c.onHide)h.c.onHide(h);else{h.w.hide()&&h.o&&h.o.remove()}return false}};var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version=="6.0"),i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),O=function(h){if(ie6)h.o&&h.o.html('<p style="width:100%;height:100%"/>').prepend(i)||(!$('iframe.jqm',h.w)[0]&&h.w.prepend(i));f(h)},f=function(h){try{$(':input:visible',h.w)[0].focus()}catch(e){}},F=function(t){$()[t]("keypress",x)[t]("keydown",x)[t]("mousedown",x)},x=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);r&&f(h);return!r},HS=function(w,e,y){var s=[];w.each(function(){s.push(this._jqm)});$(e).each(function(){if(this[y])$.extend(this[y],s);else{this[y]=s;$(this).click(function(){for(var i in{jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return false})}});return w}})(jQuery);

Cart={initialize:function(){$('#view-cart-link').click(Cart.showCart);$('#cart-container').jqm({overlay:30,overlayClass:'jqmOverlay'})},showCartDialog:true,cartContainer:'cart-contents',webroot:'',showCart:function(e){stopEvent(e);Cart.showLoader();$('#'+Cart.cartContainer).load(Cart.webroot+'cart/',{},function(){Cart.hideLoader();if(Cart.showCartDialog===true){$('#cart-container').jqmShow()}})},hide:function(e){stopEvent(e);$('#cart-container').jqmHide()},add:function(e){stopEvent(e);Cart.showLoader();$('#'+Cart.cartContainer).load(Cart.webroot+'cart/add/',{product_id:$('#product_id').val(),type_id:$('#type_id').val(),option_id:$('#option_id').val(),fabric_id:$('#fabric_id').val()},function(){Cart.hideLoader();if(Cart.showCartDialog===true){$('#cart-container').jqmShow()}})},remove:function(e,removeLink){stopEvent(e);Cart.showLoader();$('#'+Cart.cartContainer).load(removeLink.getAttribute('href'),{},function(){Cart.hideLoader();Cart.adjustShipping()})},updateOption:function(element){Cart.showLoader();var temporary_id=element.getAttribute('lineitem');var type_id=element.id.substr(5,element.id.length);var newValue=element.options[element.selectedIndex].value;$('#'+Cart.cartContainer).load(Cart.webroot+'cart/updateOption/',{lineItem:temporary_id,type_id:type_id,value:newValue},function(){Cart.hideLoader()})},updateColor:function(element){Cart.showLoader();var temporary_id=element.getAttribute('lineitem');var newValue=element.options[element.selectedIndex].value;var type_id=element.id.substr(5,element.id.length);$('#'+Cart.cartContainer).load(Cart.webroot+'cart/updateColor/',{lineItem:temporary_id,type_id:type_id,color:newValue},function(){Cart.hideLoader()})},quantityKeypress:function(element){Cart.lastKeypress=new Date().getTime();setTimeout(function(){var currentTime=new Date().getTime();if(currentTime-Cart.lastKeypress>1000){Cart.updateQuantity(element)}},1100)},updateQuantity:function(element){var temporary_id=element.getAttribute('lineitem');var newValue=element.value;if(newValue!==null&&newValue!==''){Cart.showLoader();if(newValue===0){Cart.removeFromCart(temporary_id)}else{$('#'+Cart.cartContainer).load(Cart.webroot+'cart/updateQuantity/',{lineItem:temporary_id,value:newValue},function(){Cart.hideLoader();$('#quantity_'+temporary_id)[0].focus();Cart.adjustShipping()})}}},adjustShipping:function(){if(typeof Shipping != 'undefined'){Shipping.calculate()}},showLoader:function(){var height=($(window).myHeight()/2)+$(window).scrollTop()-($('#loading-image').height()/2);var width=($(window).width()/2)-($('#loading-image').width()/2);$('#loading-image').css({'display':'block','top':height,'left':width})},hideLoader:function(){$('#loading-image').hide()}};$(Cart.initialize);stopEvent=function(e){if(e.preventDefault!==undefined){e.preventDefault()}if(e.stopPropagation!==undefined){e.stopPropagation()}e.returnValue=false};jQuery.fn.myHeight=function(h){var name="Height";return this[0]==window?!jQuery.browser.msie&&self["inner"+name]||jQuery.boxModel&&document.documentElement["client"+name]||document.body["client"+name]:this[0]==document?Math.max(document.body["scroll"+name],document.body["offset"+name]):h==undefined?(this.length?jQuery.css(this[0],n):null):this.css(n,h.constructor==String?h:h+"px")};

$(document).ready(function(){$("input:text, input:password, textarea").focus(function(){$(this).attr({className:"textbox-focus"})}).blur(function(){$(this).attr({className:"textbox"})})});

Adroit = {};
Adroit.stopEvent = function(e) {
    if(e.preventDefault !== undefined) {
        e.preventDefault();
    }
    if(e.stopPropagation !== undefined) {
        e.stopPropagation();
    }
    e.returnValue = false;
}
$(function() {
	var img = new Image();	
    $('.rollover').hover(function() {
    	var currentImg = $(this).attr('src');
		$(this).attr('src', $(this).attr('hover'));
		$(this).attr('hover', currentImg);
	}, function() {
		var currentImg = $(this).attr('src');
		$(this).attr('src', $(this).attr('hover'));
		$(this).attr('hover', currentImg);
	}).each(function() {
		img.src = $(this).attr('hover');
	});
});
