﻿/*
----------------------------------------------------------
	Initialize Namespace
----------------------------------------------------------
*/
window.Website = {
	Utils: {},
	Form: {},
	Pages: {
		Global: {},
		Review: {},
		Startpage: {}
	},
	Plugins: {},
	Effects: {}
};

/*
----------------------------------------------------------
GLOBAL PROPERTIES
----------------------------------------------------------
*/

$(document).ready(function() {
	Website.IE6 = false;
	Website.IE = false;
	if (($.browser.msie) && (parseInt($.browser.version) < 7)) {
		Website.IE6 = true;
	}
	if (($.browser.msie)) {
		Website.IE = true;
	}

	$(document).keypress(function(e) {

		try {

			if (e.which == 13 && !$(e.target).is("textarea")) {
				e.returnValue = false;
				e.cancel = true;
				e.preventDefault();
				e.stopPropagation();
			}

		}

		catch (exp) { }

	});
});


/*
----------------------------------------------------------
WEBSITE.UTILS
----------------------------------------------------------
*/


Website.Utils.Bubble = function(strHeadline, strMessage, strId, posLeft, Zindex) {
	this.Headline = strHeadline,
    this.Message = strMessage,
    this.ElementID = strId,
    this.PositionLeft = posLeft,
    this.ZIndex = Zindex,
    this.Init = function() {

    	if (Zindex == null)
    		Zindex = 1000;
    	if (this.PositionLeft == null)
    		this.PositionLeft = 0;

    	var strHtml = "";
    	strHtml += "<div class=\"bubble\" id=\"" + this.ElementID + "Bubble\" style=\"z-index:" + this.ZIndex + "\">";
    	strHtml += "<div class=\"content\">";
    	strHtml += "<label class=\"headline\" style=\"display:block;\">" + this.Headline + "</label>";
    	strHtml += this.Message;
    	strHtml += "</div>"
    	strHtml += "<div class=\"bottom\"></div>";
    	strHtml += "</div>";
    	$(document.body).prepend(strHtml);

    	var pos = $("#" + this.ElementID).offset();

    	$("#" + this.ElementID + "Bubble").css({ left: pos.left + (this.PositionLeft), top: pos.top - ($("#" + this.ElementID + "Bubble").height() + 45) });
    },
    this.Show = function() {
    	$("#" + this.ElementID + "Bubble").show();
    },
    this.Toggle = function() {
    	if ($("#" + this.ElementID + "Bubble:visible").length > 0)
    		$("#" + this.ElementID + "Bubble").hide();
    	else
    		$("#" + this.ElementID + "Bubble").show();
    },
    this.Hide = function() {
    	$("#" + this.ElementID + "Bubble").hide();
    }
}

Website.Utils.BubbleAlt = function(strHeadline, strMessage, strId, posLeft, posTop, Zindex) {
	this.Headline = strHeadline,
    this.Message = strMessage,
    this.ElementID = strId,
    this.PositionTop = posTop,
    this.PositionLeft = posLeft,
    this.ZIndex = Zindex,
    this.Init = function() {

    	if (Zindex == null)
    		Zindex = 1000;
    	if (this.PositionLeft == null)
    		this.PositionLeft = 0;

    	var strHtml = "";
    	strHtml += "<div class=\"bubble-alt\" id=\"" + this.ElementID + "Bubble\" style=\"z-index:" + this.ZIndex + "\">";
    	strHtml += "<div class=\"content\">";
    	strHtml += "<label class=\"headline\" style=\"display:block;\">" + this.Headline + "</label>";
    	strHtml += this.Message;
    	strHtml += "</div>"
    	strHtml += "<div class=\"bottom\"></div>";
    	strHtml += "</div>";
    	$(document.body).prepend(strHtml);

    	var pos = $("#" + this.ElementID).offset();
    	$("#" + this.ElementID + "Bubble").css({ left: (pos.left + (this.PositionLeft)), top: pos.top + (this.PositionTop) });
    },
    this.Show = function() {
    	$("#" + this.ElementID + "Bubble").show();

    	$("#" + this.ElementID + "Bubble").click(function() {
    		$(this).hide();
    	})
    },
    this.Hide = function() {
    	$("#" + this.ElementID + "Bubble").hide();
    }
}

Website.Utils.RenderLinkSifr = function(strSelector, strColor, strHoverColor) {
	sIFR.replace(
		sIFR_DEFAULT, {
			selector: strSelector,
			css: [
				'.sIFR-root {}',
				'a { text-decoration: none; }',
				'a:link { color: ' + strColor + ' }',
				'a:hover { color: ' + strHoverColor + '; }'
				],
			fitExactly: true,
			wmode: 'transparent'
		});

}

Website.Utils.RenderSifr = function(strSelector, strColor) {
	sIFR.replace(
		sIFR_DEFAULT, {
			selector: strSelector,
			css: [
				'.sIFR-root {color: ' + strColor + '; }'
			],
			fitExactly: true,
			wmode: 'transparent'
		});

}

Website.Utils.SetPageOpacity = function(opacity1, opacity2, bgcolor, Zindex) {
	$("#opacity").remove();
	$("body").append("<div id=\"opacity\" class=\"opacity\" style=\"filter:alpha(opacity=" + opacity1 + ");-moz-opacity:." + opacity2 + ";opacity:." + opacity2 + "; z-index:" + Zindex + "; background-color:" + bgcolor + ";\"></div>");
	var intWidth = $(document).width();
	var intHeight = $(document).height();
	$("#opacity").css("width", intWidth + "px");
	$("#opacity").css("height", intHeight + "px");
}

Website.Utils.RemovePageOpacity = function() {
	$("#opacity").remove();
}

Website.Utils.PageEqualHeight = function() {
//	var leftHeight = $("#ContainerContentLeft").outerHeight();
//	var rightHeight = $("#ContainerContentMain").outerHeight();
//	var rightLargeHeight = $("#ContainerContentMainLarge").outerHeight();
//	var moduleHeight = $("#ContainerContentRight").outerHeight();

//	if (rightLargeHeight != null) {
//		if (leftHeight > rightLargeHeight)
//			rightLargeHeight = leftHeight;
//		else
//			leftHeight = rightLargeHeight;

//		if (leftHeight < moduleHeight && rightLargeHeight < moduleHeight) {
//			leftHeight = moduleHeight;
//			rightLargeHeight = moduleHeight;
//		}
//	}
//	else {
//		if (leftHeight > rightHeight)
//			rightHeight = leftHeight;
//		else
//			leftHeight = rightHeight;

//		if (leftHeight < moduleHeight && rightHeight < moduleHeight) {
//			leftHeight = moduleHeight;
//			rightHeight = moduleHeight;
//		}
//	}

//	if (Website.IE6) {
//		$("#ContainerContentLeft,#SubMenu").css("height", leftHeight + "px");
//		$("#ContainerContentMain,#ContainerContentMain div.wrapper").css("height", rightHeight + "px");
//	}
//	else {
//		$("#ContainerContentLeft,#SubMenu").css("min-height", leftHeight + "px");
//		$("#ContainerContentMain,#ContainerContentMain div.wrapper").css("min-height", rightHeight + "px");
//	}
}

Website.Utils.Center = function(elementWidth, elementHeight, elementID) {
	var intWidth = $(window).width();
	var intHeight = $(window).height();
	$('#' + elementID).css("left", (intWidth / 2) - (elementWidth / 2))
	$('#' + elementID).css("top", (intHeight / 2) - (elementHeight / 2) + $(window).scrollTop())
}

Website.Utils.RenderTable = function() {
	// Every other tr has darker background
	$('table.data-table tbody').each(function() {
		$('tr:even td:not(.empty)', this).addClass('zebra');
	});

	// Every other td has even darker background
	$('table.data-table tbody tr').each(function() {
		$('td:not(.zebra):odd', this).addClass('zLight');
	});

	// Every other td has even darker background
	$('table.data-table tbody tr').each(function() {
		$('td.zebra:odd', this).addClass('zebraGray');
	});

	// Every other th has darker background
	$('table.data-table tbody').each(function() {
		$('th:odd', this).addClass('zebraDarkTh');
	});
}


/*
----------------------------------------------------------
WEBSITE.FORM
----------------------------------------------------------
*/
Website.Form.DoSubmit = function(strID) {
	$("#" + strID).click();
}

$(document).ready(function() {
	$('input.watermark').focus(function() {
		if ($(this).val() == this.defaultValue)
			$(this).val('');
		else if ($(this).val() == '')
			$(this).val(this.defaultValue);
	});

	$('input.watermark').blur(function() {
		if ($(this).val() == this.defaultValue)
			$(this).val('');
		else if ($(this).val() == '')
			$(this).val(this.defaultValue);
	});

	$('input.textbox').each(function() {
		var elementSize = $(this).attr("rel");
		if (elementSize == null)
			elementSize = "large";
		$(this).addClass(elementSize).wrap('<div class="textbox-left textbox-' + elementSize + '-left"></div>').wrap('<div class="textbox-right textbox-' + elementSize + '-right"></div>');
	});

	$('input.submit-button').each(function() {
		$(this).hide();
		var strText = $(this).attr("value");
		var strID = $(this).attr("id");

		$(this).after('<a href="javascript:Website.Form.DoSubmit(\'' + strID + '\')" id="lnk' + strID + '" class="submit-button"><span>' + strText + '</span></a>');

		$('#lnk' + strID).hover(function() {
			$(this).addClass("submit-button-hover");
			$(this + " span").addClass("submit-button-hover");
		},
		    function() {
		    	$(this).removeClass("submit-button-hover");
		    	$(this + " span").removeClass("submit-button-hover");
		    })
	});

});