﻿
$(document).ready(function() {

    SetPanelLinks();
    SetExternalLinks();
    SetFormDefaultText();
    SetBackgroundImage();

});

function SetBackgroundImage() {
    var rn = Math.floor(Math.random() * 6)
    $("#pagecontent").addClass("content_background" + rn).show("slow");
}

function SetPanelLinks() {

	$('.linkpanel')
		.click(function() {
			var link = $(this).find("a").eq(0);
			location.href = link.attr("href");
		})
		.mouseover(function() {
			$(this).css("cursor", "pointer");
			$(this).toggleClass("linkpanel_hover", true);
		})
		.mouseout(function() {
			$(this).css("cursor", "default");
			$(this).toggleClass("linkpanel_hover", false);
		});
}



function SetExternalLinks() {
	$("a[rel]='external'").each(function() {
		$(this).attr("target", "_blank");
	});
}

function SetFormDefaultText() {

	// Find controls
	var inputs = $('input[type=text], textarea');

	// Set defaults
	inputs.each(function() {
		
		var title = $(this).attr("title");
		
	}).focus(function() {
		val = this.value
		if (this.value .charAt(0) == '-') {this.value=''}
		
	}).blur(function() {
		
		if (this.value == '' && val .charAt(0) == '-') {this.value= val}
	})

	
}

var ContentDataTabs = function(linkSelector, contentSelector, targetSelector) {

	$(linkSelector + ' ' + contentSelector).addClass("hidden");
	$(linkSelector).eq(0).addClass("active");
	CutAndPasteContent($(linkSelector + ' ' + contentSelector).eq(0), targetSelector);

	$(linkSelector).click(function() {
		$(linkSelector).removeClass("active");
		$(this).addClass("active");
		CutAndPasteContent($(this).find(contentSelector).eq(0), targetSelector);
	});

	function CutAndPasteContent(source, targetSelector) {
		$(targetSelector)
			.css({ opacity: 0.1 })
			.html(source.html())
			.animate({ opacity: 1.0 }, 200)
	}
}

