﻿// MAIN
$(document).ready(function() {

	$(".fancybox").each(function() {
		if (this.parentNode.className != "fancyboxWrapLink") {
			$(this).wrap("<a class=\"fancyboxWrapLink\" href=\"" + this.src + "\" title=\"" + this.alt + "\"></a>");
		}
	});
	$(".fancyboxWrapLink").each(function() {
		$(this).wrap('<div class=\"fancyboxWrap\"></div>');
		var caption;
		var tmp = $(this).html();
		if (this.title != "" && this.title != undefined && this.title != null) {
			caption = '<div class="caption">' + this.title + '</div>';
			$(this).html(caption + tmp);
		}
		else if ($("img", this).attr("alt") != "" && $("img", this).attr("alt") != undefined) {
			caption = '<div class="caption">' + $("img", this).attr("alt") + '</div>';
			$(this).html(caption + tmp);
			$(this).attr("title", $("img", this).attr("alt"));
		}

	});
	$(".fancyboxWrap").each(function() {
		if ($.browser.msie) {
			$(this).css("width", $("img", this).width() + 4 + "px");
		}

		if ($("img", this).attr("align") == "right") {
			$(this).css("float", "right");
		}
		else {
			$(this).css("float", "left");
		}

	});
	$(".fancyboxWrap").each(function() {
		//$(this).css("width", $("img", this).width() + "px");
		//		$(this).css("height", $("img", this).height() + "px");

	});

	$(".fancyboxWrapLink").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true });

	var gcookie = getCookie('fontsize');
	if (isNaN(gcookie) || gcookie == null || gcookie > 60) {
	    $("body").css("font-size", "16px");
	} else {
	    $("body").css("font-size", getCookie('fontsize') + "px");
	}

	var defaultFontSize = parseInt(new String($("body").css("font-size")).replace("px", ""));
	var stepFontSize = Math.round(defaultFontSize * 0.2);

	$("#biggerFont").click(function() {
	    var tmp = parseInt(new String($("body").css("font-size")).replace("%", ""));
	    tmp = tmp + stepFontSize;
	    $("body").css("font-size", tmp + "px");
	    setCookie('fontsize', tmp, 365);
	});
	$("#smallerFont").click(function() {
	    var tmp = parseInt(new String($("body").css("font-size")).replace("%", ""));
	    tmp = tmp - stepFontSize;
	    $("body").css("font-size", tmp + "px");
	    setCookie('fontsize', tmp, 365);
	});
});

function setCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function MoveFlyoutToMouse(anchor, flyout)
{
	var location = Sys.UI.DomElement.getLocation($get(anchor));
	var popUp = $get(flyout);

	popUp.style.position = 'absolute';
	popUp.style.top = (location.y + 32) + 'px';
	popUp.style.left = (location.x + 32) + 'px';
}

function getAbsoluteLeft(o)
{
	// Get an object left position from the upper left viewport corner
//	o = document.getElementById(objectId)
	oLeft = o.offsetLeft // Get left position from the parent object
	while (o.offsetParent != null)
	{ // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	return oLeft
}

function getAbsoluteTop(o)
{
	// Get an object top position from the upper left viewport corner
//	o = document.getElementById(objectId)
	oTop = o.offsetTop // Get top position from the parent object
	while (o.offsetParent != null)
	{ // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	return oTop
}