// JavaScript Document


jQuery( function($) {

	
	var width = $(".titleBox h1").width();
	var height =  $(".titleBox h1").height();
	$(".titleBox .h1Container").width(width + 15);
	$(".titleBox .h1Container").height(height);
	$(".titleBox .h1Container").css("opacity", 0.9);
	$(".titleBox .h1Container").show();

	$(".titleBox h1").css("position","absolute");
	$(".titleBox h1").css("top",25);
	$(".titleBox h1").css("left",30);
	$(".titleBox h1").show();
	

		
	makeRoundedBox("roundedWhite",		"roundedWhiteContainer",		"roundedWhiteTop",		"roundedWhiteBottom"		);
	makeRoundedBox("roundedWhite2col",	"roundedWhiteContainer2col",	"roundedWhiteTop2col",	"roundedWhiteBottom2col"	);
	makeRoundedBox("roundedWhite1col",	"roundedWhiteContainer1col",	"roundedWhiteTop1col",	"roundedWhiteBottom1col"	);
	makeRoundedBox("roundedFooter",		"roundedFooterContainer",		"roundedFooterTop",		"roundedFooterBottom"		);
	
	$('.titleBox , .titleBoxBig').ifixpng();		// fix the transparency of the corners in IE6

	if ($.toNum($.cookie("userid")) > 0) {
		$("#signInButton").text("My account");
		$("#signInButton").attr("href", "/cgi-bin/mydetails.pl");
	}
	
	
	$(".doButtonSubmit").click(function(){
				$(this).parents('form').submit();
				return false;
	});
	
	// hack the bottom of rounded boxes to use padding not margin.
	$(".roundedWhiteContainer").find("p:last").addClass("lastInRoundBox");

});


function makeRoundedBox(boxClass, containerClass, topClass, bottomClass) {
	
	$("." + boxClass).each(
							function() {
								
									// first make sure that this box isn't alreay in it's contain Class e.g. manually made
									// rounded boxes that contain google ads etcs
									
									var el = $(this);		// the current element, that we want to make into a rounded box
									
								
									if (el.parents("." + containerClass).length <=0) {
																				
									
										var newContainerClasses = [];						// array to keep the classes in for our new container
										var currentClasses = el.attr('class').split(' '); 	// the current classes that apply to the box
										
										for (i=0; i<currentClasses.length; i++) {		// for each of the current classes
											var className = currentClasses[i];
										
											if (className != boxClass) {				// not if it's the one that makes us a box
												el.removeClass(className);				// remove it from the orig box
												newContainerClasses.push(className);	// and add it to the new box container instead.
											}
										}
										
										
										// should this rounded box have useful magic content?
										var rel = el.attr("rel") || "";
										if ((rel != "") && ($(rel).length == 1)) {
											var content = $(rel).html();
											content = content.replace(/<script.*?<\/script>/, "");	// remove scripts as they break the world
											el.html(content);
											$(rel).remove();
										}
								
										// wrap the orig box in a new container with the ld classes
										el.wrap("<div class='" + containerClass + " " + newContainerClasses.join(" ") + "'></div>");	
										
										
										var container = el.parent("." + containerClass);
										$(container).prepend("<div class='" + topClass + "'></div>");	// add the box tops
										$(container).append("<div class='" + bottomClass + "'></div>");	// add the box bottoms
									}
							}
						);
	
	
	$('.' + boxClass + ', .' + topClass + ', .' + bottomClass).ifixpng();		// fix the transparency of the corners in IE6
}

function digg() {
	

	var url = window.location;
	var title = $("title").text() || "LastMinuteMusicians";
	if (title.length > 75) {
		title = title.substr(0,75)
	}
	var description = $("meta[NAME=Description]").attr("CONTENT");

	var media= "news";
	var topic = "music";

	//console.log("http://digg.com/submit?url=" + escape(url) + "&title=" + escape(title) + "&bodytext=" + escape(description) + "&media=" + media + "&topic=" + topic);
	window.location="http://digg.com/submit?url=" + escape(url) + "&title=" + escape(title) + "&bodytext=" + escape(description) + "&media=" + media + "&topic=" + topic;
		
	
}
