//boulderbalm.com
jQuery.noConflict();
var ie6=(jQuery.browser.msie && jQuery.browser.version < 7),d=document,de=d.documentElement,w=window;

/* heavily modified Thickbox 3.1
 * Original By Cody Lindley (http://www.codylindley.com)
 */
function tb_init(domChunk){
	jQuery(domChunk||'a.thickbox,area.thickbox,input.thickbox').click(function(){
		tb_show(this.title||this.name||"",this.href||this.alt,this.rel||false);
		this.blur();
		return false;
	});
}

function tb_show(caption, url, imageGroup){
	try{
		if(ie6){
			TB_SaveWidth=jQuery("body").css("width");
			jQuery("body","html").css({height:"100%", width:"100%"});
			jQuery("html").css("overflow","hidden");
			if (d.getElementById("TB_HideSelect")===null){//iframe to hide select elements in ie6
				jQuery("body").append("<iframe id='TB_HideSelect'></iframe>");
			}
		}
		if(d.getElementById("TB_o")===null){
			jQuery("body").append("<div id='TB_o'></div><div id='TB_w'></div><div id='TB_load'></div>");
			jQuery("#TB_o").click(tb_remove);
		}

		var baseURL=url,
			i=url.indexOf("?"),
			TB_w=jQuery("#TB_w"),
			TB_o=jQuery("#TB_o");
		if(i!==-1){ //if there is a query string involved
			baseURL=url.substr(0,i);
		}else{ 
			url+="?";
		}

		if(/\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/.test(baseURL.toLowerCase())||(/TBimg/.test(url))){//code to show images
			var TB_PrevCaption="",
				TB_PrevURL="",
				TB_PrevHTML="",
				TB_NextCaption="",
				TB_NextURL="",
				TB_NextHTML="",
				TB_imageCount="",
				TB_FoundURL=false;
			if(imageGroup){
				var TB_TempArray=jQuery("a[@rel="+imageGroup+"]").get();
				for (var TB_Counter=0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML==="")); TB_Counter++){
					if (!(TB_TempArray[TB_Counter].href==url)){
						if (TB_FoundURL){
							TB_NextCaption=TB_TempArray[TB_Counter].title;
							TB_NextURL=TB_TempArray[TB_Counter].href;
							TB_NextHTML="<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
						}else{
							TB_PrevCaption=TB_TempArray[TB_Counter].title;
							TB_PrevURL=TB_TempArray[TB_Counter].href;
							TB_PrevHTML="<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
						}
					}else{
						TB_FoundURL=true;
						TB_imageCount="Image " + (TB_Counter + 1) +" of "+ TB_TempArray.length;
					}
				}
			}
			imgPreloader=new Image();
			imgPreloader.onload=function(){
				imgPreloader.onload=null;
				// Resizing large images - orginal by Christian Montoya edited by me.
				var pagesize=tb_getPageSize();
				var x=pagesize[0]-150,y=pagesize[1]-150,
					imageWidth=imgPreloader.width,
					imageHeight=imgPreloader.height;
				if (imageWidth > x){
					imageHeight=imageHeight * (x / imageWidth);
					imageWidth=x;
					if (imageHeight > y){
						imageWidth=imageWidth * (y / imageHeight);
						imageHeight=y;
					}
				}else if (imageHeight > y){
					imageWidth=imageWidth * (y / imageHeight);
					imageHeight=y;
					if (imageWidth > x){
						imageHeight=imageHeight * (x / imageWidth);
						imageWidth=x;
					}
				}
				// End Resizing
				TB_WIDTH=imageWidth + 30;
				TB_HEIGHT=imageHeight + 60;
				TB_w.append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src=\"s/tb-close.png\"></a></div>");
				jQuery("#TB_closeWindowButton").click(tb_remove);
				if (!(TB_PrevHTML==="")){
					function goPrev(){
						if(jQuery(d).unbind("click",goPrev)){jQuery(d).unbind("click",goPrev);}
						TB_w.remove();
						jQuery("body").append("<div id='TB_w'></div>");
						tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
						return false;
					}
					jQuery("#TB_prev").click(goPrev);
				}
				if (!(TB_NextHTML==="")){
					function goNext(){
						jQuery("#TB_w").remove();
						jQuery("body").append("<div id='TB_w'></div>");
						tb_show(TB_NextCaption, TB_NextURL, imageGroup);
						return false;
					}
					jQuery("#TB_next").click(goNext);
				}

				d.onkeydown=function(e){ 	
					var keycode=e?e.which:event.keyCode;
					if(keycode==27){
						tb_remove();
					}else if(keycode==190){ // display previous image
						if(!(TB_NextHTML=="")){
							d.onkeydown="";
							goNext();
						}
					}else if(keycode==188){ // display next image
						if(!(TB_PrevHTML=="")){
							d.onkeydown="";
							goPrev();
						}
					}
				};

				jQuery("#TB_ImageOff").click(tb_remove);
				tb_loaded();
			};
			imgPreloader.src=url;
		}else{//code to show html
			var params=tb_parseQuery(url.replace(/^[^\?]+\??/,''));
			TB_WIDTH=(params.width*1) + 30 || 800; //default
			TB_HEIGHT=(params.height*1) + 45 || 500; //default
			var ajaxContentW=TB_WIDTH - 30,
			ajaxContentH=TB_HEIGHT - 45;
			if(url.indexOf('TB_iframe') !=-1){// iframe?
				var urlNoQuery=url.split('TB_');
				jQuery("#TB_iframeContent").remove();
				if(params.modal !="true"){//iframe no modal
					TB_w.append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src=\"s/tb-close.png\"></a></div></div>");
				}else{//iframe modal
					TB_o.unbind();
				}
				TB_w.append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
			}else{// !iframe, ajax
				if(TB_w.css("display") !="block"){
					if(params.modal !="true"){//ajax no modal
						TB_w.append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'><img src=\"s/tb-close.png\"></a></div></div><div id='TB_c' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
					}else{//ajax modal
						TB_o.unbind();
						TB_w.append("<div id='TB_c' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
					}
				}else{//this means the window is already up, we are just loading new content via ajax
					var c=jQuery("#TB_c")[0];
					c.style.width=ajaxContentW +"px";
					c.style.height=ajaxContentH +"px";
					c.scrollTop=0;
					jQuery("#TB_ajaxWindowTitle").html(caption);
				}
			}
			var TB_c=jQuery("#TB_c");
			jQuery("#TB_closeWindowButton").click(tb_remove);
			if(url.indexOf('TB_inline') !=-1){	
				TB_c.append(jQuery('#' + params.inlineId).children());
				TB_w.unload(function (){
					jQuery('#' + params.inlineId).append( jQuery("#TB_c").children() ); // move elements back when you're finished
				});
				tb_loaded();
			}else if(url.indexOf('TB_iframe') !=-1){
				tb_position();
				if(jQuery.browser.safari){//safari needs help because it will not fire iframe onload
					tb_loaded();
				}
			}else{
				if(/\.swf$/.test(baseURL.toLowerCase())){
					TB_c.html("<object type=\"application/x-shockwave-flash\" data=\""+url+"\" width=\""+params.width+"\" height=\""+params.height+"\"><param name=\"movie\" value=\""+url+"\"/><param name=\"allowScriptAccess\" value=\"always\"/></object>");
					tb_loaded();
				}else if(/\.pdf$/.test(baseURL.toLowerCase())){
					TB_c.html("<embed type=\"application/pdf\" src=\""+url+"\" width=\"100%\" height=\"100%\"></embed>");
					tb_loaded();
				}else{
					TB_c.load(url+="&random="+new Date().getTime(),'',tb_loaded(1));
				}
			}
		}
		if(!params.modal){
			d.onkeyup=function(e){
				if ((e?e.which:event.keyCode)==27){
					tb_remove();
				}	
			};
		}
	}catch(e){}
}

function tb_loaded(ajax){
	tb_position();
	if (ajax){
		tb_init("#TB_c a.thickbox");
	}
	jQuery("#TB_load").fadeOut("slow");
	jQuery("#TB_w").css({display:"block"});

}

function tb_showIframe(){
	jQuery("#TB_load").fadeOut("slow");
	jQuery("#TB_w").css({display:"block"});
}

function tb_remove(){
	jQuery("#TB_imageOff,#TB_closeWindowButton").unbind("click");
	jQuery("#TB_w,#TB_load").fadeOut("fast",function(){jQuery('#TB_w,#TB_o,#TB_HideSelect,#TB_load').trigger("unload").unbind().remove();});
	if(ie6){
		jQuery("body","html").css({height: "auto", width: "auto"});
		jQuery("html").css("overflow","");
		jQuery("body").css("width",TB_SaveWidth);
	}
	d.onkeydown="";
	d.onkeyup="";
	return false;
}

function tb_position(){
	jQuery("#TB_w").css({marginLeft:'-'+parseInt((TB_WIDTH/2),10)+'px',width:TB_WIDTH+'px'});
	if (!ie6){
		jQuery("#TB_w").css({marginTop:'-'+parseInt((TB_HEIGHT/2),10)+'px'});
	}
}

function tb_parseQuery(query){
	var Params={};
	if(query){
		var Pairs=query.split(/[;&]/);
		for(var i=0;i<Pairs.length;i++){
			var KeyVal=Pairs[i].split('=');
			if(!KeyVal||KeyVal.length!=2){continue;}
			var key=unescape(KeyVal[0]),
				val=unescape(KeyVal[1]);
				Params[key]=val.replace(/\+/g,' ');
		}
	}
	return Params;
}

function tb_getPageSize(){
	return [w.innerWidth||self.innerWidth||(de&&de.clientWidth)||d.body.clientWidth, w.innerHeight||self.innerHeight||(de&&de.clientHeight)||d.body.clientHeight];
}


// Copyright 2009 Boulderbalm
var sShow,ssInt,slide=0,homeSlides=[
	['s/sOB.jpg','find.php?c=original'],
	['s/sBB.jpg','find.php?c=brazen'],
	['s/sAH.jpg','find.php?c=active'],
	['s/s2.jpg','find.php?a=social']
	];
function sSwap(){jQuery('#slide').html('<a href="'+sShow[slide][1]+wlink+'"><img src="'+sShow[slide][0]+'" /></a>').fadeIn("normal");}
function sF(){slide++;if (slide==sShow.length){slide=0;};jQuery('#slide').fadeOut("normal",sSwap);}
function slideShow(s){clearInterval(ssInt);sShow=s;ssInt=setInterval(sF,8000);}
function findPage(f){w.location="find.php?"+f;}
function JaddToCart(formId,parameters){
	var f=document.getElementById(formId);
	jQuery.post('index.php',jQuery(formId),function(){});
}
function pageStart(){
	slideShow(homeSlides);
	tb_init();
	imgLoader = new Image();
	imgLoader.src = "s/TB_load.gif";
;
}

