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,wName,w,h) {
  var popuper = window.open(newURL, wName,'scrollbars=0, resizeable=0, 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+$/,"");
}
function verticalCenter(target){
	var wH = $(window).height();
	var oH = $(target).height();
	if ( wH <= oH ){
		$(target).css({
			top: "10px",
			marginTop: "0px"
		});
	}
	else{
		$(target).css({
			top: "50%",
			marginTop: "-"+oH/2+"px"
		});
	}
}
function viewClip(url,title){
	var title = title;
	var x = title.indexOf(" ");
	if( x == -1 ){ x = title.length }
	var eTitle = title.substr(0,x);
	var urlString = "/video.php?url="+url+"&title="+title+"&width=390&height=293";
	popup(urlString,"nada",431,398);
}
function viewClip2(url,title){
	var title = title;
	var x = title.indexOf(" ");
	if( x == -1 ){ x = title.length }
	var eTitle = title.substr(0,x);
	var urlString = "/video.php?url="+url+"&title="+title+"&width=480&height=270&style=2";
	popup(urlString,"nada2",521,375);
}

$(document).ready(function(){
	//external link setup
	$("a[href^='http://']").each(function(){
		$(this).attr({
			href: "javascript:visit('" + $(this).attr('href') + "')"
		});
	});
	loc = location.pathname;
	//mainmenu current 
	$("#mainmenu a[href='"+loc+"']").addClass("current").parent().append("<div class='marker' style='width:"+($("#mainmenu .current").width() - 43)+"px'></div>");
	
	//mainmenu rollovers setup
	$("#mainmenu a:not(.current)").hover(
		function () {
			$(this).parent().append("<div class='marker' style='width:"+($(this).width() - 43)+"px'></div>");
			
			$("#mainmenu .current").parent().contents(".marker").css({
				display: "none"
			});
		},
		function () {
			$(this).parent().contents().remove(".marker");
			$("#mainmenu .current").parent().contents(".marker").css("display","block");
		}
	);
	//background rollovers setup
	$(".rollover").hover(
		function () {
			var h = "0px -" + $(this).css("height");
			$(this).css("background-position",h);
		},
		function () {
			$(this).css("background-position","0px 0px");
		}
	);
	//mailto setup
	$(".mailto").each(function(){
		var name = $(this).attr("title");
		var html = "<a href='mailto:" + name + "@corner24.com'>" + name + "@corner24.com</a>";
		$(this).html(html);
	});
	//png fix
	$(".png").pngfix();
	//video clip image links
	$(".itemImage").each(function(){
		var x = $(this).siblings("p.link").children("a").attr("onclick");
		$(this).wrapInner("<a></a>").children("a").attr("onclick",x);
	});
});