function writeFlash(url,w,h,id,bg,trans) {
var html = "";
html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="' + w + '" height="' + h + '" id="'+ id + '">\n';
html += '<param name="movie" value="' + url + '" />\n';
html += '<param name="quality" value="high" />\n';
html += '<param name="bgcolor" value="' + bg + '" />\n';
html += '<param name="scale" value="noscale" />\n';
if (trans == 1) {html += '<param name="wmode" value="transparent" />\n';}
html += '<!--[if !IE]> <-->\n';
html += '<object data="' + url + '" width="' + w + '" height="' + h + '" type="application/x-shockwave-flash" name="'+ id + '">\n';
html += '<param name="quality" value="high" />\n';
html += '<param name="scale" value="noscale" />\n';
html += '<param name="bgcolor" value="' + bg + '" />\n';
html += '<param name="pluginurl" value="http://www.macromedia.com/go/getflashplayer" />\n';
if (trans == 1) {html += '<param name="wmode" value="transparent" />\n';}
html += ' FAIL (the browser should render some flash content, not this).\n';
html += ' </object>\n';
html += '<!--> <![endif]-->\n';
html += '</object>\n';
document.write(html);
}

function visit(newURL) {
  var site = window.open(newURL, 'website','scrollbars=1, resizable=1, location=1, menubar=1, status=1, toolbar=1, height=768, width=1024');
  site.window.focus();
}
function popup(newURL) {
  var popuper = window.open(newURL, 'popup','scrollbars=0, resizeable=0, width=450, height=550');
  popuper.window.focus();
}
function rand(min,max){
	var $min = min;
	var $max = max + 1;
	random_num = Math.floor($min + ($max-$min)*Math.random());
	return random_num;
}
String.prototype.decode = function(){
	return this.replace(/&lt;/gi,"<").replace(/&gt;/gi,">").replace(/&quot;/gi,"\"");
}
String.prototype.decodeNoP = function(){
	return this.replace(/&lt;p&gt;/gi,"").replace(/&lt;\/p&gt;/gi,"<br /><br />").replace(/&lt;/gi,"<").replace(/&gt;/gi,">").replace(/&quot;/gi,"\"");
	return this.replace(/&lt;/gi,"<").replace(/&gt;/gi,">").replace(/&quot;/gi,"\"");
}
String.prototype.decodeOneP = function(){
	return this.replace(/&lt;p&gt;/gi,"").replace(/&lt;\/p&gt;/gi,"<br />").replace(/&lt;/gi,"<").replace(/&gt;/gi,">").replace(/&quot;/gi,"\"");
	return this.replace(/&lt;/gi,"<").replace(/&gt;/gi,">").replace(/&quot;/gi,"\"");
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
String.prototype.checkEmail = function(){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(this)){ r = true }
	else{ r = false }
	return (r)
}
 
String.prototype.pad = function(len, pad, dir) {
	
	var STR_PAD_LEFT = 1;
	var STR_PAD_RIGHT = 2;
	var STR_PAD_BOTH = 3;
 
	if (typeof(len) == "undefined") { len = 0; }
	if (typeof(pad) == "undefined") { pad = ' '; }
	if (typeof(dir) == "undefined") { dir = STR_PAD_RIGHT; }
 	var str = this; 

	if (len + 1 >= str.length) {
 
		switch (dir){
 
			case STR_PAD_LEFT:
				str = Array(len + 1 - str.length).join(pad) + str;
			break;
 
			case STR_PAD_BOTH:
				var right = Math.ceil((padlen = len - str.length) / 2);
				var left = padlen - right;
				str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
			break;
 
			default:
				str = str + Array(len + 1 - str.length).join(pad);
			break;
 
		} // switch
 
	}
 
	return str;
 
}
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return false;
}
function verticalPos(){
	var hHeight = $(window).height();
	if ( hHeight <= 652 ){
		$("#outerWrapper").css({
			top: "0px",
			marginTop: "0px"
		});
	}
	else{
		$("#outerWrapper").css({
			top: "50%",
			marginTop: "-325px"
		});
	}
}

function popupPic(sPicURL) {
  window.open( "/popup.html?"+sPicURL, "",  
  "resizable='1', height='200', width='200'");
}

$(document).ready(function(){
	//external link setup
	$("a[href^='http://'],a[href*='pdf']").not("a[href*=secure.lionsbreath.ca]").each(function(){
		$(this).not("[href*='javascript']").attr({
			href: "javascript:visit('" + $(this).attr('href') + "')"
		});
	});
	//mainmenu current
	var cM = $("body").attr("class");
	$("#mainMenu a[href*="+cM+"]").addClass("current").parent().addClass("current");
	//mainmenu rollovers setup
	$("#mainMenu a:not(.current)").hover(
		function () {
			$(this).parent().css("background-position","0px 2px");
		},
		function () {
			$(this).parent().css("background-position","0px 22px");
		}
	);
	// Store menu last class
	$('#leftMenu li:last').addClass('last');
	
	//vertical positioning
	verticalPos();
	
	//newsletter switch bg
	$("#page_email").focus(function(){
		$(this).css("background-position","0px 0px");
	}).blur(function(){
		$(this).css("background-position","0px -25px");
	});
	
	//newsletter validate
	$("#page_email_go").click(function(){
		var email = $("#page_email").val();
		
		if ( email.checkEmail() ){
		
			var sendData = {
				email_address: email
			};
			$.ajax({
			  type: "GET",
			  url: "/_scripts/process_email.asp",
			  data: sendData,
			  dataType: "text",
			  error: function(){
			     	alert('Our site is experiencing difficulties, please check back later.');
			  },
			  complete: function() {
					$("#newsletter_signup").replaceWith("<div id='newsletter_thanks'> </div>");
			  }
			});
		}
		else{
			$("#page_email_label").css("background-image","url(/_images/page-newsletter-error.png)");
		}
	});
	
	// setup scroll
	/*if (!$.browser.safari){
		$(".jScrollPane").jScrollPane({
			scrollbarWidth : 13,
			dragMinHeight : 45,
			dragMaxHeight : 238
		});
	}*/
	/*$.post("/admin/call.lookup-sku.asp",
		{ sku: product_sku},
		function(data){
		$("#item-count").html(data);
		});
	});*/	
});

$(window).load(function(){

	//if ($.browser.safari){
	// setup scroll
		$(".jScrollPane").jScrollPane({
			scrollbarWidth : 13,
			dragMinHeight : 45,
			dragMaxHeight : 238
		});
	//}
	
});

$(window).resize(function(){
	verticalPos();
})
