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,w,h,n) {
  var popuper = window.open(newURL,n,'scrollbars=0, resizeable=0, width='+w+', height='+h);
  popuper.window.focus();
}
function popupColors(newURL,w,h,n) {
  var popuper = window.open(newURL,n,'scrollbars=1, resizeable=1, width='+w+', height='+h);
  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.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
};
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
};
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
};

$(document).ready(function(){
	//external link setup
	$("a[href^='http://']").each(function(){
		$(this).attr({
			href: "javascript:visit('" + $(this).attr('href') + "')"
		}).removeAttr("target");
	});
	//background rollovers setup
	$(".rollover").hover(
		function () {
			var h = "0px -" + $(this).css("height");
			$(this).css("background-position",h);
		},
		function () {
			$(this).css("background-position","0px 0px");
		}
	);
	//dropdown setup
	$(".submenu").hover(
		function(){
			$(this).contents("ul").css("display","block");
		},
		function(){
			$(this).contents("ul").css("display","none");
		}
	);
	//mailto setup
	$(".mailto").each(function(){
		var name = $(this).attr("title");
		var html = "<a href='mailto:" + name + "@ainsliewear.com'>" + name + "@ainsliewear.com</a>";
		$(this).html(html);
	});
	//products switch
	$("#switch").toggle(
		function(){
			$(".photos").css("display",'none');
			$(".drawings").css("display",'block');
		},
		function(){
			$(".drawings").css("display",'none');
			$(".photos").css("display",'block');
		}
	);
	//leftmenu rollover
	$("#leftmenu li").hover(
		function(){
			$(this).addClass("hover");
		},
		function(){
			$(this).removeClass("hover");
		}
	).click(function(){
		var link = $(this).children("a").attr("href");
		window.location = link;
	});
	//leftmenu current
	var loc = location.pathname;
	$("#leftmenu a[href='"+loc+"']").parent().addClass("current");

});