var backgroundImageHeight;
var backgroundImageWidth;
var backgroundImageRatio;

var documentHeight;
var documentWidth;
var documentRatio;

var windowHeight;
var windowWidth;
var windowRatio;

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22290709-4']);
_gaq.push(['_trackPageview']);

function backgroundLoad(screenWidth, backgroundImage) {
	$("#background").attr("src", "http://"+ window.location.hostname +"/source/script_excl/background.php?screenWidth="+ screenWidth +"&background="+ backgroundImage);
}

function backgroundResize() {
	if ( documentRatio < backgroundImageRatio ) {
		$("#background").width(documentHeight * backgroundImageRatio);
		$("#background").height(documentHeight); }
	else {
		$("#background").width(documentWidth);
		$("#background").height(documentWidth / backgroundImageRatio); }

	if ( $("#background").width() > documentWidth ) {
		var backgroundImageLeft = 0-(($("#background").width() - documentWidth) / 2);
		$("#background").css("left", backgroundImageLeft +"px"); }
	else {
		$("#background").css("left", "0px"); }
}

function documentResize() {
	windowHeight = $(window).height();
	windowWidth = $(window).width();
	windowRatio = (windowWidth / windowHeight);

	var headerHeight = $("#layout_header").height();
	var footerHeight = $("#layout_footer").height();
	$("#layout_body").height(windowHeight - headerHeight - footerHeight);

	var menuPaddingTop = $("#body_menu").css("padding-top");
	var menuPaddingBottom = $("#body_menu").css("padding-bottom");
	var widgetHeight = windowHeight - headerHeight - footerHeight - menuPaddingTop.replace("px", "") - menuPaddingBottom.replace("px", "");
	$("#widget_container").height(widgetHeight);

	var submenuHeight = $("#header_submenu").height();
	$("#header_menu").height(headerHeight - submenuHeight);
	$("#header_menu ul li").css("margin-top", (headerHeight - 50) +"px");
	$("#header_menu img.header_logo").height(headerHeight - 45);

	var bodyWidth = $("#layout_body").width();
	var footerPaddingLeft = $("#layout_footer").css("padding-left");
	var footerPaddingRight = $("#layout_footer").css("padding-right");
	$("#layout_header").width(bodyWidth);
	$("#layout_footer").width(bodyWidth - footerPaddingLeft.replace("px", "") - footerPaddingRight.replace("px", ""));

	documentHeight = $(document).height();
	documentWidth = $(document).width();
	documentRatio = (documentWidth / documentHeight);
}

$(window).load(function() {
	$("a[rel]").bind("click", function() { $(this).attr("target", $(this).attr("rel")); });

	$("input.input_special").css({
		"-webkit-border-radius": "0px"});

	if ( $.browser.mozilla && $.browser.version > "3.6" ) {
		$("a.submit_special").css({"background-image": "-moz-linear-gradient(top, rgba(246,246,246,1), rgba(241,241,241,1))"});

		$("a.submit_special").hover(function() {
			$(this).css({"background-image": "-moz-linear-gradient(top, rgba(146,146,146,1), rgba(133,133,133,1))"}); },
		function() {
			$(this).css({"background-image": "-moz-linear-gradient(top, rgba(246,246,246,1), rgba(241,241,241,1))"}); });
	}

	if ( $.browser.webkit ) {
		$("a.submit_special").css({"background-image": "-webkit-gradient(linear, center top, center bottom, from(rgba(246,246,246,1)), to(rgba(241,241,241,1)))"});

		$("a.submit_special").hover(function() {
			$(this).css({"background-image": "-webkit-gradient(linear, center top, center bottom, from(rgba(146,146,146,1)), to(rgba(133,133,133,1)))"}); },
		function() {
			$(this).css({"background-image": "-webkit-gradient(linear, center top, center bottom, from(rgba(246,246,246,1)), to(rgba(241,241,241,1)))"}); });
	}

	if ( $.browser.opera ) {
		$("a.submit_special").css({"background-image": "-o-linear-gradient(top, rgba(246,246,246,1), rgba(241,241,241,1))"});

		$("a.submit_special").hover(function() {
			$(this).css({"background-image": "-o-linear-gradient(top, rgba(146,146,146,1), rgba(133,133,133,1))"}); },
		function() {
			$(this).css({"background-image": "-o-linear-gradient(top, rgba(246,246,246,1), rgba(241,241,241,1))"}); });
	}

	if ( $.browser.msie ) {
		$("a.submit_special").css({
			"-ms-filter": "progid:DXImageTransform.Microsoft.gradient(startColorstr='#F6F6F6', endColorstr='#F1F1F1', GradientType=0)",
			"filter": "progid:DXImageTransform.Microsoft.gradient(startColorstr='#F6F6F6', endColorstr='#F1F1F1', GradientType=0)"});

		$("a.submit_special").hover(function() {
			$(this).css({
				"-ms-filter": "progid:DXImageTransform.Microsoft.gradient(startColorstr='#A4A4A4', endColorstr='#858585', GradientType=0)",
				"filter": "progid:DXImageTransform.Microsoft.gradient(startColorstr='#A4A4A4', endColorstr='#858585', GradientType=0)"}); },
		function() {
			$(this).css({
				"-ms-filter": "progid:DXImageTransform.Microsoft.gradient(startColorstr='#F6F6F6', endColorstr='#F1F1F1', GradientType=0)",
				"filter": "progid:DXImageTransform.Microsoft.gradient(startColorstr='#F6F6F6', endColorstr='#F1F1F1', GradientType=0)"}); });
	}

	backgroundImageHeight = $("#background").height();
	backgroundImageWidth = $("#background").width();
	backgroundImageRatio = (backgroundImageWidth / backgroundImageHeight);

	documentResize();
	backgroundResize();

	$(".cornerMe").corner();
	$(".cornerMeBottom").corner("BL BR 9px");
	$(".cornerMeSmall").corner("2px");
});

$(window).load(function() {
	$("#forground").css("display", "none");
});

$(window).resize(function() {
	documentResize();
	backgroundResize();
});

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
