﻿// Common JavaScript Library for CIRIS

var _PX = document.childNodes ? 'px' : 0;
var _HideTimer;

function PreLoadImage(url, width, height)
{
    img = new Image(width, height);
    img.src = url;
}

function SelectMainMenuItem(id)
{
    document.getElementById('MainMenuItem' + id).className += ' MMSelected';
}

function SelectSubMenuItem(id)
{
    document.getElementById('SubMenuItem' + id).className += ' SMSelected';
}

function ShowLoginMenu()
{
    clearTimeout(_HideTimer); 
    
    var loginButton = document.getElementById('LoginButton');
    loginButton.style.background = 'transparent url(Resources/MainMenu/LoginButtonHover.png) no-repeat left top';

    var loginMenu = document.getElementById('LoginMenu');
    loginMenu.style.left = (findPosX(loginButton) + 3) + _PX;
    loginMenu.style.display = 'block';
    
    var intWindowWidth = GetWindowWidth();
    if (parseInt(loginMenu.style.left) + parseInt(loginMenu.offsetWidth) > intWindowWidth)
        loginMenu.style.left = (intWindowWidth - parseInt(loginMenu.offsetWidth) - 5) + _PX;
}

function StartLoginMenuHideTimer()
{
    _HideTimer = setTimeout('HideLoginMenu()', 800);
}

function HideLoginMenu()
{
    var loginButton = document.getElementById('LoginButton');
    loginButton.style.background = 'transparent url(Resources/MainMenu/LoginButton.png) no-repeat left top';
    
    var loginMenu = document.getElementById('LoginMenu');
    loginMenu.style.display = 'none';
}

// ---------------------------------------------------
// Helper function to get the X coordinate of the given object
// ---------------------------------------------------
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft - obj.scrollLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}


// ---------------------------------------------------
// Helper function to get the current width of the window
// ---------------------------------------------------
function GetWindowWidth()
{
//    return document.documentElement.clientWidth;
    var intWidth = 0;
    
    if (typeof( window.innerWidth ) == 'number' ) 
    {
        //Non-IE
        intWidth = window.innerWidth;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientWidth ) ) 
    {
        //IE 6+ in 'standards compliant mode'
        intWidth = document.documentElement.clientWidth;
    } 
    else if( document.body && ( document.body.clientWidth || document.body.clientWidth ) ) 
    {
        //IE 4 compatible
        intWidth = document.body.clientWidth;
    }
   
   return intWidth;
}





/*
* Metadata - jQuery plugin for parsing metadata from elements
*
* Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan
*
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
*
* Revision: $Id: jquery.metadata.js 3620 2007-10-10 20:55:38Z pmclanahan $
*
*/
(function($) { $.extend({ metadata: { defaults: { type: 'class', name: 'metadata', cre: /({.*})/, single: 'metadata' }, setType: function(type, name) { this.defaults.type = type; this.defaults.name = name; }, get: function(elem, opts) { var settings = $.extend({}, this.defaults, opts); if (!settings.single.length) settings.single = 'metadata'; var data = $.data(elem, settings.single); if (data) return data; data = "{}"; if (settings.type == "class") { var m = settings.cre.exec(elem.className); if (m) data = m[1]; } else if (settings.type == "elem") { if (!elem.getElementsByTagName) return; var e = elem.getElementsByTagName(settings.name); if (e.length) data = $.trim(e[0].innerHTML); } else if (elem.getAttribute != undefined) { var attr = elem.getAttribute(settings.name); if (attr) data = attr; } if (data.indexOf('{') < 0) data = "{" + data + "}"; data = eval("(" + data + ")"); $.data(elem, settings.single, data); return data; } } }); $.fn.metadata = function(opts) { return $.metadata.get(this[0], opts); }; })(jQuery);



/**
* swapImage - jQuery plugin for swapping image
*
* Copyright (c) 2008 tszming (tszming@gmail.com)
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
(function($) { $.swapImage = function(i, preload, repeat, swapInEvent, swapOutEvent) { $.swapImage.files = {}; $.swapImage.data = {}; $.swapImage.init = function() { var id = $.data(this); var data = $(this).metadata(); $.swapImage.data[id] = $.swapImage.data[id] || {}; if (typeof data.src != "undefined") { $.swapImage.data[id]["src"] = data.src; $.swapImage.files[data.src] = false } $.each($.grep([[data.sin, "sin"], [data.sout, "sout"]], function(n) { return (typeof n[0] != "undefined" && n[0].length > 0) }), function() { var arr = this[0]; var vname = this[1]; for (var i = 0; i < arr.length; i++) { var idx = data[vname][i].indexOf(":"); var selection = data[vname][i].substring(0, idx); var file = data[vname][i].substring(idx + 1); $.swapImage.data[id][vname] = $.swapImage.data[id][vname] || []; if (idx > 1) { $.swapImage.data[id][vname].push([selection, file]); $.swapImage.files[file] = false } else { $.swapImage.data[id][vname].push([file]) } } }) }; $.swapImage.preload = function() { $.each($.swapImage.files, function(k, v) { if (v == false) { $.swapImage.files[k] = true; var img = new Image(); img.src = k } }) }; $.swapImage.swapIn = function() { $.swapImage.swap(this, "sin") }; $.swapImage.swapOut = function() { $.swapImage.swap(this, "sout") }; $.swapImage.swap = function(obj, a) { var id = $.data(obj); if (typeof $.swapImage.data[id][a] != "undefined") { for (var i = 0; i < $.swapImage.data[id][a].length; i++) { if ($.swapImage.data[id][a][i].length > 1) { $($.swapImage.data[id][a][i][0]).attr("src", $.swapImage.data[id][a][i][1]) } else { $($.swapImage.data[id][a][i][0]).each($.swapImage._swap) } } } else { $.swapImage._swap.call(obj) } }; $.swapImage._swap = function(obj) { var id = $.data(this); var data = $.swapImage.data[id]; if (typeof data.src != "undefined") { var tmp = data.src; data.src = this.src; this.src = tmp } }; $(document).ready(function() { if (typeof repeat == "undefined") { repeat = true } if (typeof preload == "undefined") { preload = true } $(i).each($.swapImage.init); if (typeof swapInEvent == "undefined" && typeof swapInEvent == "undefined") { swapInEvent = "mouseenter"; swapOutEvent = "mouseleave" } if (repeat) { if (typeof swapOutEvent != "undefined") { $(i).bind(swapInEvent, $.swapImage.swapIn).bind(swapOutEvent, $.swapImage.swapOut) } else { $(i).bind(swapInEvent, $.swapImage.swapIn) } } else { $(i).one(swapInEvent, $.swapImage.swapIn) } if (preload) { $(i).each($.swapImage.preload) } }) } })(jQuery);




/*
reflection.js for jQuery v1.02
(c) 2006-2008 Christophe Beyls <http://www.digitalia.be>
MIT-style license.
*/
(function(a) { a.fn.extend({ reflect: function(b) { b = a.extend({ height: 0.33, opacity: 0.5 }, b); return this.unreflect().each(function() { var c = this; if (/^img$/i.test(c.tagName)) { function d() { var j, g = Math.floor(c.height * b.height), k, f, i; if (a.browser.msie) { j = a("<img />").attr("src", c.src).css({ width: c.width, height: c.height, marginBottom: -c.height + g, filter: "flipv progid:DXImageTransform.Microsoft.Alpha(opacity=" + (b.opacity * 100) + ", style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy=" + (b.height * 100) + ")" })[0] } else { j = a("<canvas />")[0]; if (!j.getContext) { return } f = j.getContext("2d"); try { a(j).attr({ width: c.width, height: g }); f.save(); f.translate(0, c.height - 1); f.scale(1, -1); f.drawImage(c, 0, 0, c.width, c.height); f.restore(); f.globalCompositeOperation = "destination-out"; i = f.createLinearGradient(0, 0, 0, g); i.addColorStop(0, "rgba(255, 255, 255, " + (1 - b.opacity) + ")"); i.addColorStop(1, "rgba(255, 255, 255, 1.0)"); f.fillStyle = i; f.rect(0, 0, c.width, g); f.fill() } catch (h) { return } } a(j).css({ display: "block", border: 0 }); k = a(/^a$/i.test(c.parentNode.tagName) ? "<span />" : "<div />").insertAfter(c).append([c, j])[0]; k.className = c.className; a.data(c, "reflected", k.style.cssText = c.style.cssText); a(k).css({ width: c.width, height: c.height + g, overflow: "hidden" }); c.style.cssText = "display: block; border: 0px"; c.className = "reflected" } if (c.complete) { d() } else { a(c).load(d) } } }) }, unreflect: function() { return this.unbind("load").each(function() { var c = this, b = a.data(this, "reflected"), d; if (b !== undefined) { d = c.parentNode; c.className = d.className; c.style.cssText = b; a.removeData(c, "reflected"); d.parentNode.replaceChild(c, d) } }) } }) })(jQuery);
