$(document).ready(function(){
													 
	$(".menu UL LI:has(UL.sub)").hover(function(){
		$(".qtmedia").hide();
		$(this).find("UL.sub").fadeIn("fast");
	},function(){
		$(this).find("UL.sub").hide();
		$(".qtmedia").show();
	});
	
	if ($("DIV.expand").html() != null) {
		var firstDiv = 232;
		var charPerRow = 54;
		var sizeReduction = 3;
		var newArr = Array();
		var count = 0;
		var len = $("DIV.expand").html().length;
		var content = $("DIV.expand").html();
		for (var i=firstDiv; i<len; i += charPerRow ) {
			var pos = content.indexOf(" ",i);
			if (pos >= 0) {
				var endpos = content.indexOf(" ",i+charPerRow-(count*sizeReduction));
				i=i-(count*sizeReduction);
				if (endpos >= 0) {
					newArr[count++] = "<div>"+content.substr(pos+1,endpos-pos-1)+"</div>";
				} else {
					newArr[count++] = "<div>"+content.substr(pos+1)+"</div>";
				} // end else
			} // end if
		} // end for
		var pos = content.indexOf(" ",firstDiv);
		$("DIV.expand").html(content.substr(0,pos)+"\r\n"+newArr.join("\r\n"));
	} // end if
	
	// ONCLICK
	$("DIV.content UL LI A").click(function() {
		loadMedia($(this));
	});

	// INITIAL LOAD
	function loadMedia(a) {
		if (typeof(a) == 'undefined') a = $("DIV.content UL LI A:first");
		var pos = $(a).find("IMG").attr("src").lastIndexOf("/");
		var result = $(a).find("IMG").attr("src").substr(0,pos) + "/full/" + $(a).find("IMG").attr("src").substr(pos+1);
		$("#fullImg").attr("src",result);
		$(".qtmedia").each(function() {
			$(".qtmedia").media({ 
				width:     320, 
				height:    256, 
				autoplay:  true, 
				bgColor:	 '#000000',
				src:       result.replace('jpg','mov'), 
				caption:   false // supress caption text 
			});
		});
	} // end function
	
	loadMedia();
});

