//when page loads start standard functions
function initialize() {
	//replace external links with open in new window
	externalLinks();
}

window.onload = initialize;


function $import(src){
	var scriptElem = document.createElement('script');
  scriptElem.setAttribute('src',src);
	scriptElem.setAttribute('type','text/javascript');
	document.getElementsByTagName('head')[0].appendChild(scriptElem);
}


// import with a random query parameter to avoid caching
function $importNoCache(src){
	var ms = new Date().getTime().toString();
	var seed = "?" + ms; 
	$import(src + seed);
}


function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors .length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
			anchor.title = (anchor.title != "") ? anchor.title+" (opens in a new window) ": "opens in a new window";
			anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
//			anchor.onclick = 'javascript: pageTracker._trackPageview (\'/outgoing/'+anchor.href+'\');';
			var track = anchor.href;
			track = track.replace('http://','');
			anchor.onclick = function() { 
				pageTracker._trackPageview('/outgoing/'+track);
			}
		}
	}
}


function prepareInput(id,value)
{
	if(document.getElementById(id).value==value) document.getElementById(id).value='';
}


//jquery functions
$(document).ready(function() {
	initialize();

	var mydate = new Date();

	if ( $(".editable-item").length < 1 ) {
		$(".job_entry").each(function(){
			$jobText = $(".job_text", $(this));
			$this = $(this);
			if($jobText.html()==""){
				$(this).hide();
			}
			else {
				$(".more_content a", $(this)).click(function(){
					$jobEntry = $(this).parent().parent();
					$jobEntry.animate({ 
						height: $(".job_text", $jobEntry).height()
					}, 1500 );
					$(this).parent().css("display","none");
				});
			}
		});

		if ( $("div.scrollableArea").length > 0 ) {
			$("#makeMeScrollable").smoothDivScroll({scrollWrapper: "div.scrollableArea", scrollableArea: "div.scrollableArea ul", autoScrollDirection: "backandforth"});
		}

	}

	$("#main_picture #thumbnails .thumbnail img").mouseover(function(){
		$("#main_picture #main_image img").attr("src",$(this).attr("rel"));
		$("#main_picture #main_image img").attr("alt",$(this).attr("alt"));
	});

	$(".testimonial ul").each(function(){
		$("li:first-child", this).addClass("first");
	});

	// Reset Font Size
	var originalFontSize = $("html").css("font-size");
		$(".resetFont").click(function(){
		$("html").css("font-size", originalFontSize);
		$.cookie("cookieFontSize", "", { expires: -1 });
	});
	
	// Increase Font Size
	$(".enlarge-text").click(function(){
		var currentFontSize = $("html").css("font-size");
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		$("html").css("font-size", newFontSize);
		$.cookie("cookieFontSize", newFontSize, { expires: 7 });
		return false;
	});
	
	// Decrease Font Size
	$(".reduce-text").click(function(){
		var currentFontSize = $("html").css("font-size");
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		$("html").css("font-size", newFontSize);
		$.cookie("cookieFontSize", newFontSize, { expires: 7 });
		return false;
	});

	//cookie code
	if($.cookie("cookieFontSize")!="")
	{
		$("html").css("font-size", $.cookie("cookieFontSize"));
	}

	var mydate = new Date();
	$("#year").html("&copy; " + mydate.getFullYear() + " Newsmakers");

});
