(function($) { if (typeof $.fn.replace == 'undefined') $.fn.replace = function(a) { return this.after(a).remove(); }; if (typeof $.fn.replaceContent == 'undefined') $.fn.replaceContent = function(a) { return this.empty().append(a); }; 
$.taconite = $.xmlExec = function(xml) { $.taconite.impl.process(xml); }
$.taconite.version = [2,0,9]; $.taconite.debug = 0; $.taconite.lastTime = 0; $.taconite._httpData = $.httpData; $.httpData = $.taconite.detect = function(xhr, type) { var ct = xhr.getResponseHeader('content-type'); $.taconite.log('[AJAX response] content-type: ', ct, '; status: ', xhr.status, ' ', xhr.statusText, '; has responseXML: ', xhr.responseXML != null); var data = $.taconite._httpData(xhr, type); if (data && data.documentElement) { var root = data.documentElement.tagName; $.taconite.log('XML document root: ', root); if (root == 'taconite') { $.taconite.log('taconite command document detected'); $.taconite(data); } } else $.taconite.log('httpData: response is not XML (or not "valid" XML)'); return data; }; $.taconite.enableAutoDetection = function(b) { $.httpData = b ? $.taconite.detect : $.taconite._httpData; }; $.taconite.log = function() { if (!$.taconite.debug || !window.console || !window.console.log) return; if (!$.taconite.log.count++) $.taconite.log('Plugin Version: ' + $.taconite.version.join('.')); window.console.log('[taconite] ' + [].join.call(arguments,'')); }; $.taconite.log.count = 0; $.taconite.impl = { trimHash: {wrap:1}, convert: function(s) { var doc; $.taconite.log('attempting string to document conversion'); try { if (window.ActiveXObject) { doc = new ActiveXObject('Microsoft.XMLDOM'); doc.async = 'false'; doc.loadXML(s); } else { var parser = new DOMParser(); doc = parser.parseFromString(s, 'text/xml'); } } catch(e) { if (window.console && window.console.error) window.console.error('[taconite] ERROR parsing XML string for conversion: ' + e); throw e; } var ok = doc && doc.documentElement && doc.documentElement.tagName != 'parsererror'; $.taconite.log('conversion ', ok ? 'successful!' : 'FAILED'); return doc; }, process: function(xml) { if (typeof xml == 'string') xml = this.convert(xml); if (!xml || !xml.documentElement) { $.taconite.log('$.taconite invoked without valid document; nothing to process'); return; } try { var t = new Date().getTime(); $.taconite.impl.process1(xml.documentElement.childNodes); $.taconite.lastTime = (new Date().getTime()) - t; $.taconite.log('time to process response: ' + $.taconite.lastTime + 'ms'); } catch(e) { if (window.console && window.console.error) window.console.error('[taconite] ERROR processing document: ' + e); throw e; } }, process1: function(commands) { for(var i=0; i < commands.length; i++) { if (commands[i].nodeType != 1) continue; var cmdNode = commands[i], cmd = cmdNode.tagName; if (cmd == 'eval') { var js = (cmdNode.firstChild ? cmdNode.firstChild.nodeValue : null); $.taconite.log('invoking "eval" command: ', js); if (js) $.globalEval(js); continue; } var q = cmdNode.getAttribute('select'); var jq = $(q); if (!jq[0]) { $.taconite.log('No matching targets for selector: ', q); continue; } var a = []; if (cmdNode.childNodes.length > 0) { for (var j=0,els=[]; j < cmdNode.childNodes.length; j++) els[j] = this.createNode(cmdNode.childNodes[j]); a.push(this.trimHash[cmd] ? this.cleanse(els) : els); } else { var n = cmdNode.getAttribute('name'); var v = cmdNode.getAttribute('value'); if (n !== null) a.push(n); if (v !== null) a.push(v); for (var j=1; true; j++) { v = cmdNode.getAttribute('arg'+j); if (v === null) break; a.push(v); } } if ($.taconite.debug) { var arg = els ? '...' : a.join(','); $.taconite.log("invoking command: $('", q, "').", cmd, '('+ arg +')'); } jq[cmd].apply(jq,a); } }, cleanse: function(els) { for (var i=0, a=[]; i < els.length; i++) if (els[i].nodeType == 1) a.push(els[i]); return a; }, createNode: function (node) { var type = node.nodeType; if (type == 1) return this.createElement(node); if (type == 3) return this.fixTextNode(node.nodeValue); if (type == 4) return document.createTextNode(node.nodeValue); return null; }, fixTextNode: function(s) { if ($.browser.msie) s = s.replace(/\n/g, '\r'); return document.createTextNode(s); }, createElement: function (node) { var e, tag = node.tagName.toLowerCase(); if ($.browser.msie && (tag == 'input' || tag == 'button')) {var type = node.getAttribute('type');
if (type == 'radio' || type == 'checkbox') return document.createElement('<input ' + this.copyAttrs(null, node, true) + '>');
else if (tag == 'button')
e = document.createElement('<button ' + this.copyAttrs(null, node, true) + '>');} 
if (!e) { e = document.createElement(tag); this.copyAttrs(e, node); } if($.browser.msie && !e.canHaveChildren) { if(node.childNodes.length > 0) e.text = node.text; } else { for(var i=0, max=node.childNodes.length; i < max; i++) { var child = this.createNode (node.childNodes[i]); if(child) e.appendChild(child); } } return e; }, copyAttrs: function (dest, src, inline) { for (var i=0, attr=''; i < src.attributes.length; i++) { var a = src.attributes[i], n = $.trim(a.name), v = $.trim(a.value); if (inline) attr += (n + '="' + v + '" '); else if (n == 'style') { dest.style.cssText = v; dest.setAttribute(n, v); } else $.attr(dest, n, v); } return attr; } }; })(jQuery); 

jQuery.fn.ajaxSubmit = function(options) { if (typeof options == 'function') options = { success: options }; options = jQuery.extend({ url: this.attr('action') || '', method: this.attr('method') || 'GET' }, options || {}); options.success = options.success || options.after; options.beforeSubmit = options.beforeSubmit || options.before; options.type = options.type || options.method; var a = this.formToArray(options.semantic); if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) return this; var veto = {}; jQuery.event.trigger('form.submit.validate', [a, this, options, veto]); if (veto.veto) return this; var q = jQuery.param(a); if (options.type.toUpperCase() == 'GET') { options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; options.data = null; } else options.data = q; var $form = this, callbacks = []; if (options.resetForm) callbacks.push(function() { $form.resetForm(); }); if (options.clearForm) callbacks.push(function() { $form.clearForm(); }); if (!options.dataType && options.target) { var oldSuccess = options.success || function(){}; callbacks.push(function(data, status) { jQuery(options.target).attr("innerHTML", data).evalScripts().each(oldSuccess, [data, status]); }); } else if (options.success) callbacks.push(options.success); options.success = function(data, status) { for (var i=0, max=callbacks.length; i < max; i++) callbacks[i](data, status); }; jQuery.event.trigger('form.submit.notify', [this, options]); jQuery.ajax(options); return this; }; jQuery.fn.ajaxForm = function(options) { return this.each(function() { jQuery("input:submit,input:image,button:submit", this).click(function(ev) { var $form = this.form; $form.clk = this; if (this.type == 'image') { if (ev.offsetX != undefined) { $form.clk_x = ev.offsetX; $form.clk_y = ev.offsetY; } else if (typeof jQuery.fn.offset == 'function') { var offset = jQuery(this).offset(); $form.clk_x = ev.pageX - offset.left; $form.clk_y = ev.pageY - offset.top; } else { $form.clk_x = ev.pageX - this.offsetLeft; $form.clk_y = ev.pageY - this.offsetTop; } } setTimeout(function() { $form.clk = $form.clk_x = $form.clk_y = null; }, 10); }) }).submit(function(e) { jQuery(this).ajaxSubmit(options); return false; }); }; jQuery.fn.formToArray = function(semantic) { var a = []; if (this.length == 0) return a; var form = this[0]; var els = semantic ? form.getElementsByTagName('*') : form.elements; if (!els) return a; for(var i=0, max=els.length; i < max; i++) { var el = els[i]; var n = el.name; if (!n) continue; if (semantic && form.clk && el.type == "image") { if(!el.disabled && form.clk == el) a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y}); continue; } var v = jQuery.fieldValue(el, true); if (v === null) continue; if (v.constructor == Array) { for(var j=0, jmax=v.length; j < jmax; j++) a.push({name: n, value: v[j]}); } else a.push({name: n, value: v}); } if (!semantic && form.clk) { var inputs = form.getElementsByTagName("input"); for(var i=0, max=inputs.length; i < max; i++) { var input = inputs[i]; var n = input.name; if(n && !input.disabled && input.type == "image" && form.clk == input) a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y}); } } return a; }; jQuery.fn.formSerialize = function(semantic) { return jQuery.param(this.formToArray(semantic)); }; jQuery.fn.fieldSerialize = function(successful) { var a = []; this.each(function() { var n = this.name; if (!n) return; var v = jQuery.fieldValue(this, successful); if (v && v.constructor == Array) { for (var i=0,max=v.length; i < max; i++) a.push({name: n, value: v[i]}); } else if (v !== null && typeof v != 'undefined') a.push({name: this.name, value: v}); }); return jQuery.param(a); }; jQuery.fn.fieldValue = function(successful) { var val=[], name; for (var i=0, max=this.length; i < max; i++) { var el = this[i]; var v = jQuery.fieldValue(el, successful); if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) continue; name = name || el.name; if (name != el.name) continue; v.constructor == Array ? jQuery.merge(val, v) : val.push(v); } return val; }; jQuery.fieldValue = function(el, successful) { var n = el.name, t = el.type, tag = el.tagName.toLowerCase(); if (typeof successful == 'undefined') successful = true; if (successful && ( !n || el.disabled || t == 'reset' || (t == 'checkbox' || t == 'radio') && !el.checked || (t == 'submit' || t == 'image') && el.form && el.form.clk != el || tag == 'select' && el.selectedIndex == -1)) return null; if (tag == 'select') { var index = el.selectedIndex; if (index < 0) return null; var a = [], ops = el.options; var one = (t == 'select-one'); var max = (one ? index+1 : ops.length); for(var i=(one ? index : 0); i < max; i++) { var op = ops[i]; if (op.selected) { var v = jQuery.browser.msie && !(op.attributes['value'].specified) ? op.text : op.value; if (one) return v; a.push(v); } } return a; } return el.value; }; jQuery.fn.clearForm = function() { return this.each(function() { jQuery('input,select,textarea', this).clearFields(); }); }; jQuery.fn.clearFields = jQuery.fn.clearInputs = function() { return this.each(function() { var t = this.type, tag = this.tagName.toLowerCase(); if (t == 'text' || t == 'password' || tag == 'textarea') this.value = ''; else if (t == 'checkbox' || t == 'radio') this.checked = false; else if (tag == 'select') this.selectedIndex = -1; }); }; jQuery.fn.resetForm = function() { return this.each(function() { if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) this.reset(); }); }; 

jQuery.fn._height = jQuery.fn.height; 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.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.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], 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 (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') { y += parseInt(jQuery.css(parent, 'borderTopWidth')) || 0; x += parseInt(jQuery.css(parent, 'borderLeftWidth')) || 0; } } while (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(parent, 'position') != 'absolute') { x += parseInt(jQuery.css(op, 'marginLeft')) || 0; y += parseInt(jQuery.css(op, 'marginTop')) || 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; } };

jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { options = options || {}; var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toGMTString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toGMTString(); } var path = options.path ? '; path=' + options.path : ''; var domain = options.domain ? '; domain=' + options.domain : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } };

$(document).ready(init);

function init() {
$(document.body).removeClass('jsOff').addClass("jsOn");

if (getId()=='index') {
if (!$.cookie('visit')) {
			$.cookie('visit',1,365);
        	var c=0;
		} else { 
        	var c=parseInt($.cookie('visit'))+1;
        	$.cookie('visit', c, 365);
        	var c=c>3 ? c%3 : c-1;
		};
		var set=document.getElementById('set'+c);
		$(set).show();
}

if (getId()=='contact') {
	$.ajax( {url: 'code/ajax_contact.xml', success: function() {	
	prepareContactForm();
	}})
}
if (getId()=='shop') {
	$('#shopPage').hover(function() { 
		$(this).toggleClass('pageOne'); },function() {
		if ($(this).is('.noHover')) { $(this).removeClass('noHover'); } else {
			$(this).toggleClass('pageOne'); }
	});
	$('#shopPage').click( function() {
		if($('#shopPage1').is(':visible')) {
			$('#shopPage1').fadeOut("slow",function(){
			   $('#shopPage2').fadeIn('slow');
			 });
			$(this).removeClass('pageOne');
		} else {
			$('#shopPage2').fadeOut("slow",function(){
			   $('#shopPage1').fadeIn('slow');
			 });
			$(this).addClass('pageOne');
		}
		$(this).addClass('noHover');
	});
}

fixFooter();

$('.enlarge').click(function(e) { 
var h = this.href;
var a = h.split('/')[h.split('/').length -1];
popUpShow(a);
this.blur();
cancelClick(e);
});

$('.returns').click(function(e) { 
popUpShow('returns');
this.blur();
cancelClick(e);
});
$('.wholesale').click(function(e) { 
popUpShow('wholesale');
this.blur();
cancelClick(e);
});


	var cur = getId();
	$('li a').click(function(e) { 
	if ($(this).parent().is('.'+cur)) { cancelClick(e); }
	});

};

function getId() {
return document.body.getAttribute('id');
};

function fixFooter() { var fh = $("#footer").height();
var h = $(window).height() -($('#wrapper').height()+fh);
if (h>fh) { $("#footer").css("height",h+10); }
}

function prepareContactForm() {
	if (jQuery.browser.msie) {
		$('#submitBtn').hover(function() { 
		$(this).toggleClass("over"); },function() {
		$(this).toggleClass("over"); });
		$('input').focus(function() {$(this).addClass('ieFocus')});
		$('input').blur(function() {$(this).removeClass('ieFocus')});
		$('textarea').focus(function() {$(this).addClass('ieFocus')});
		$('textarea').blur(function() {$(this).removeClass('ieFocus')})
	};
	if($.browser.safari) {
		$("input").addClass('safari');
		$("textarea").addClass('safari');
	}
		$("input").focus( function() { 
			if($(this).next().is(':visible')) { $(this).next().hide('slow')}
		});
		var options = { beforeSubmit: validate, success: showResponse };
		$('#form1').ajaxForm(options); //initiate Alsup's form plugin
};

//start of contact form module
function validate(formData, jqForm, options) { 
	var form = jqForm[0];
	if (!form.name.value) { $("#nameErr").show(); }
	if (emailCheck(form.email.value)) { $("#emailErr").show(); }
	if (!form.name.value || emailCheck(form.email.value)) return false;
};

function showResponse()  {
	$('#form1').unbind('submit'); $('#submitBtn').unbind('click');
	$('#form1').hide('slow',function() {
	$('#contactText').addClass('after');
	$('#thankYou').fadeIn('slow')});
};

function emailCheck(value) {
	return !value.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i);
};

function cancelClick(e){
		if (window.event){
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
		if (e && e.stopPropagation && e.preventDefault){
			e.stopPropagation();
			e.preventDefault();
		}
};


function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  obj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="
+ opacity + ");";
  obj.style.KHTMLOpacity = opacity/100;
  obj.style.MozOpacity = opacity/100;
  obj.style.opacity = opacity/100;
};
	
// classN is passed from the button that is clicked to call the popUp
// below it adds class to id='popUpWindow', and to call the xml file
// so the xml file has to be called the same
function popUpShow(h) {
	try {
		if (document.getElementById("popUpHideSelect") == null) {
		
			if (h=='wholesale') {
				popUpHEIGHT = 360;
				$("body").append("<iframe id='popUpHideSelect' style='opacity:0'></iframe><div id='popUpOverlay'></div><div id='popUpWindow' style='height:360px;'></div>");
				$.ajax( {url: 'code/wholesale.xml', success: function() { 
					bindCloseButton(); }
				});
			
			} else if  (h=='returns') {
				popUpHEIGHT = 500;
				$("body").append("<iframe id='popUpHideSelect' style='opacity:0'></iframe><div id='popUpOverlay'></div><div id='popUpWindow' style='height:500px;overflow: scroll;'></div>");
				$.ajax( {url: 'code/returns.xml', success: function() { 
					bindCloseButton(); }
				});
			
			} else {
				popUpHEIGHT = 360;
				$("body").append("<iframe id='popUpHideSelect' style='opacity:0'></iframe><div id='popUpOverlay'></div><div id='popUpWindow' style='height:360px;background: url(images/fullsize/"+h+") no-repeat #ddd;'></div>"); 
				$("#popUpWindow").append("<div id='popUpClose'></div>").css({display:"block"});
				bindCloseButton();
			}
		$("#popUpOverlay").click(popUpRemove);
		setOpacity(document.getElementById("popUpHideSelect"), 0);
		setOpacity(document.getElementById("popUpOverlay"), 60);
	}
	
	popUpPosition();
	
        
    document.onkeyup = function(e){   
      if (e == null) { // ie
        keycode = event.keyCode;
      } else { // mozilla
        keycode = e.which;
      }
      if(keycode == 27){ // close
        popUpRemove();
      }  
    };
    
  } catch(e) {
    alert( e );
  }
};
function bindCloseButton() {
	$('#popUpClose').hover(function() {
			$(this).addClass("hover");
	}, function() {
			$(this).removeClass("hover");
	});
	$("#popUpClose").click(popUpRemove);
}
function popUpRemove() {
	$("#popUpOverlay").unbind();
	$("#popUpCloseWindow").unbind('hover');
	$("#popUpCloseWindow").unbind('click');
	$('#form1').unbind('submit'); $('button').unbind('click'); 
	$("#popUpWindow").fadeOut("fast",function(){$('#popUpWindow, #popUpOverlay, #popUpHideSelect').remove()});
	$("#popUpLoad").remove();
	return false;
};
function popUpPosition() {

	// $("#popUpWindow").css({marginLeft:'-'+popUpWIDTH/2+"px"});
	if ( !(jQuery.browser.msie && typeof XMLHttpRequest == "function") ) { // -IE6, fix it in ie6.css
        $("#popUpWindow").css({marginTop:'-'+popUpHEIGHT/2+"px"});
     }
};