Cufon.replace("p#oneliner");
Cufon.replace("p#intro", {hover: true});
Cufon.replace("h3", {hover: true});
Cufon.replace("h4");
Cufon.replace("div#footerBoxes h2", {hover: true});
Cufon.replace("div.footerDialog h2");

$(document).ready(function() {
	if ($.browser.opera) {
		$.support.opacity = true;
	}

	window.viewportWidth = $(window).width();
	window.viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();

	// set background opacity
	if (!$("body#home").length) {
		$("#background").css("opacity", 0.2);
	}

	// set previous list opacity
	if (!($.browser.msie && parseInt($.browser.version) <= 8)) { // exclude IE *suprise*
		$(".previous", ".column1, #inTheNewsBoxFull").css("opacity", 0.5);
	
		// fade previous list
		$(".previous", ".column1, #inTheNewsBoxFull").hover(function() {
			$(this).stop().animate({ opacity: 1 }, 300);
		},function () {
			$(this).stop().animate({ opacity: 0.5 }, 300);
		});
	}
	//alert(parseInt($.browser.version));

	// set dialog overlay opacity
	$(".ui-widget-overlay").css("opacity", 0.9);

	// append and position loader
	//var loaderHTML = $("<div id=\"loader\"></div>");
	//$("body").append(loaderHTML);

	// master class rules
	if ($("#rules").length) {
		$("#rules").css("visibility", "visible");

		$("#rules").jCarouselLite({
			auto: 7000,
			speed: 750,
			easing: "easeOutBounce",
			visible: 1,
			scroll: 1,
			vertical: true,
			circular: true
		});
	}

	// twitter feed
	if ($("#twitterContainer").length) {
		$("#twitterContainer").getTwitter({
			userName: "presorockgods",
			numTweets: 4,
			loaderText: "Loading latest tweets...",
			slideIn: false,
			slideDuration: 750,
			showHeading: false,
			headingText: "Latest Tweets",
			showProfileLink: false,
			showTimestamp: true
		});
	}

	// tattoos
	if ($("#tatSlides").length) {
		$("#tatSlides").css("visibility", "visible");

		$("#tatSlides").jCarouselLite({
			auto: 2500,
			speed: 750,
			easing: "easeOutExpo",
			visible: 4,
			scroll: 1,
			vertical: false,
			circular: true,
			btnNext: ".next",
		    btnPrev: ".prev"
		});
	}

	// remove dotty backgrounds from first item in lists
	$("li:first", ".previous, #commentsList").css("background", "none");

	// input styles on focus and blur
	$("input[type='text'], textarea").focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
	}).blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
	});

	// buttons
	$("button, a.button").hover(function() {
		$(this).addClass("on");
	}, function() {
		$(this).removeClass("on");
	});

	$("button, a.button").click(function() {
		$(this).addClass("active");
	});

	// default form field values on focus and blur
	$(".defaultCheck").focus(function() {
		if (this.value == this.defaultValue) {
			this.value = "";
		}
	}).blur(function() {
		if ($.trim(this.value) == "") {
			this.value = (this.defaultValue ? this.defaultValue : "");
		}
	});

	// search form validation
	$("#searchForm").submit(function() {
		if ($("#s").attr("value") == "Search...") {
			alert("Please enter your keyword(s) to perform a search");
			$("#s").focus();
			return false;
		}
	});

	// footer box styles on hover
	$(".box, #inTheNewsBoxFull", "#footerBoxes").hover(function() {
		$(this).addClass("on");
	}, function() {
		$(this).removeClass("on");
	});

	// footer dialogs
	var footerDialogOptions = {
		modal: true,
		width: 550,
		open: function() {
			// set dialog overlay opacity
			$(".ui-widget-overlay").css("opacity", 0.90);

			// remove focus
			$(".ui-dialog-content").find(":tabbable:first").blur();
		},
		close: function() {
			$(this).dialog("destroy");
		}
	};

	$("a[href*='attention-spam'], #attentionSpamBox").click(function() {
		$("#attentionSpamDialog").dialog(footerDialogOptions);
		return false;
	});

	$(".inTheNews", "#footerBoxes").click(function() {
		$("#inTheNewsDialog").dialog(footerDialogOptions);
		return false;
	});

	$(".twitter", "#footerBoxes").click(function() {
		window.open("http://twitter.com/presorockgods");
		return false;
	});

	$(".getInTouch", "#footerBoxes").click(function() {
		$("#getInTouchDialog").dialog(footerDialogOptions);
		return false;
	});

	// linkies dialogs
	var profileDialogOptions = {
		modal: true,
		width: 700,
		open: function() {
			// set dialog overlay opacity
			//$(".ui-widget-overlay").css("opacity", 0.90);

			// remove focus
			$(".ui-dialog-content").find(":tabbable:first").blur();
		},
		close: function() {
			$(this).dialog("destroy");
		}
	};

	$("a", "#linkies, #linkr").mouseover(function() {
		$(this).children("img").stop().animate({ opacity: 0.5 }, 50).animate({ opacity: 1 }, 50);
	});

	$("a", "#linkies").click(function() {
		linkie = $(this).attr("rel");
		linkie = linkie.replace(" nofollow", "");
		$("#"+linkie).dialog(profileDialogOptions);

		return false;
	});

	// avatar switching
	$(".description", ".profile").hover(function() {
		window.original;
		window.originalSrc;

		avatar = $(this).prev();
		original = avatar.children("img");
		originalSrc = original.attr("src");
		if (original.attr("rel").length) original.attr("src", original.attr("rel"));
	}, function() {
		if (original.attr("rel").length) original.attr("src", originalSrc);
	});

	// google maps dialog
	$("#viewGoogleMap").click(function() {
		$("#googleMapsEmbed").html('<iframe id="map" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;ll=-26.062065,27.955291&amp;spn=0.014495,0.027895&amp;msid=100178707934704270301.000467d421fa132070a23&amp;output=embed"></iframe>');

		$("#googleMapsEmbed").dialog({
			modal: true,
			width: 800,
			height: 600,
			open: function() {
				// set dialog overlay opacity
				$(".ui-widget-overlay").css("opacity", 0.90);

				// remove focus
				$(".ui-dialog-content").find(":tabbable:first").blur();
			},
			close: function() {
				$(this).dialog("destroy");
			}
		});

		return false;
	});

	// slideshow dialog
	$("#viewSlideshare").click(function() {
		$("#slideshareEmbed").dialog({
			modal: true,
			width: 700,
			height: 586,
			open: function() {
				// set dialog overlay opacity
				$(".ui-widget-overlay").css("opacity", 0.90);

				// remove focus
				$(".ui-dialog-content").find(":tabbable:first").blur();
			},
			close: function() {
				$(this).dialog("destroy");
			}
		});

		return false;
	});

	// sociable
	$("a:first", ".shareLink").click(function() {
		$(this).next(".sociable").toggle();
		$(this).blur();
		return false;
	});

	$("#phone", "#contactForm").keypress(function(e) {
		return numbersOnly($(this), e);
	});

	// open links in a new window
	$("a[rel~='blank']").attr("target", "_blank");
});

/*!
 * http://www.shamasis.net/projects/ga/
 * Refer jquery.ga.debug.js
 * Revision: 13
 */
(function($){$.ga={};$.ga.load=function(uid,callback){jQuery.ajax({type:'GET',url:(document.location.protocol=="https:"?"https://ssl":"http://www")+'.google-analytics.com/ga.js',cache:true,success:function(){if(typeof _gat==undefined){throw"_gat has not been defined";}t=_gat._getTracker(uid);bind();if($.isFunction(callback)){callback(t)}t._trackPageview()},dataType:'script',data:null})};var t;var bind=function(){if(noT()){throw"pageTracker has not been defined";}for(var $1 in t){if($1.charAt(0)!='_')continue;$.ga[$1.substr(1)]=t[$1]}};var noT=function(){return t==undefined}})(jQuery);

$(window).bind("load", function() {
	$.ga.load("UA-7835200-1");

	$("a", "#thumbs, #linkies").css("background-color", "#fff");
});

// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
function numbersOnly(myfield, e, dec) {
	var key;
	var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	
	keychar = String.fromCharCode(key);
	
	// control keys and punctuation
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) || (key==45) || (key==46) || (key==120) || (key==45) || (key==40) || (key==41) || (key==32) || (key==43))
	   return true;
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	
	// decimal point jump
	else if (dec && (keychar == ".")) {
	   myfield.form.elements[dec].focus();
	   return false;
	}
	else return false;
}


// benchmarkmail stuff
function CheckField(fldName) {
	if (document.frmLB[fldName].length) {
		for (var i = 0, l = document.frmLB[fldName].length; i < l; i++) {
			if (document.frmLB[fldName].type == 'select-one') {
				if (document.frmLB[fldName][i].selected) {
					return true;
				}
			}
			else {
				if (document.frmLB[fldName][i].checked) {
					return true;
				}
			}
		}

		return false;
	}
	else {
		document.frmLB[fldName].focus();
		return (document.frmLB[fldName].value.length > 0);
	}
}

function rmspaces(x) {
	var leftx = 0;
	var rightx = x.length -1;
	
	while (x.charAt(leftx) == ' ') {
		leftx++;
	}

	while (x.charAt(rightx) == ' ') {
		--rightx;
	}

	var q = x.substr(leftx,rightx-leftx + 1);

	if ((leftx == x.length) && (rightx == -1)) {
		q ='';
	}

	return(q);
}

function checkfield(data) {
	if (rmspaces(data) == "") {
		return false;
	}
	else {
		return true;
	}
}

function isemail(data) {
	var flag = false;

	if (data.indexOf("@",0) == -1 || data.indexOf("\\",0) != -1 || data.indexOf("/",0) != -1 || !checkfield(data) || data.indexOf(".",0) == -1 || data.indexOf("@") == 0 || data.lastIndexOf(".") < data.lastIndexOf("@") || data.lastIndexOf(".") == (data.length - 1) || data.lastIndexOf("@") != data.indexOf("@") || data.indexOf(",",0) != -1 || data.indexOf(":",0) != -1 || data.indexOf(";",0) != -1) {
		return flag;
	}
	else {
		var temp = rmspaces(data);

		if (temp.indexOf(' ', 0) != -1) {
			flag = true;
		}

		var d3 = temp.lastIndexOf('.') + 4;
		var d4 = temp.substring(0,d3);
		var e2 = temp.length - temp.lastIndexOf('.') - 1;
		var i1 = temp.indexOf('@');

		if ((temp.charAt(i1+1) == '.') || (e2 > 4) || (e2 < 2)) {
			flag = true;
		}

		return !flag;
	}
}

function _checkSubmit() {
	if (!CheckField("fldfirstname")) { 
		alert("Please enter your First Name");
		return false;
	}
	
	if (!CheckField("fldlastname")) { 
		alert("Please enter your Last Name");
		return false;
	}
	
	if (!isemail(document.frmLB["fldEmail"].value)) { 
		alert("Please enter your E-mail Address");
		document.frmLB["fldEmail"].focus();
		return false;
	}
	
	return true;
}