﻿$(document).ready(function(){
	$("#page-logon").bind("click", function(){
		if($("#user-logon:visible").length!=0)
		{
			$("#user-logon").fadeOut("fast");
		}
		else
		{
			$("#user-logon").fadeIn("fast");
		}
	});
	$("#user-logon-close").bind("click", function(){
		$("#user-logon").fadeOut("fast");
	});
});

(function(){
	
	var ClientDetect = {
		init: function ()
		{
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data)
		{
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				if(dataString.indexOf(data[i].subString) != -1)
				{
						return data[i].identity;
				}
			}
		},
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				string: navigator.userAgent,
				subString: "iPhone",
				identity: "iPhone/iPod"
		    	},
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	
	};
	ClientDetect.init();
	window.$.client = { os : ClientDetect.OS };
	
})();

(function($) {
    $.fn.extend({
        SetUrlQuery: function(){
		if(arguments && arguments.length>0)
		{
			var oSearch	= new Object();
			for(var i=0; i<arguments.length; i++)
			{
				var oQuery = arguments[i].split("=");
				oSearch[oQuery[0]] = oQuery[1];
			}

			var oUrl = "";//window.location.protocol + "//" + window.location.hostname;
			if(window.location.pathname!="")
			{
				oUrl += window.location.pathname.replace(new RegExp("(\/$)|(\/\?$)|(\/default\.aspx$)|(\/default\.aspx\?$)", "g" ), "");
			}

			var oQS = "/?"
			for(var QS in oSearch)
			{
				oQS += QS + "=" + oSearch[QS] + "&";
			}
			return oUrl + oQS;
		}
		else
		{
			return document.URL;
		}
        },
        AppendUrlQuery: function(){
		if(arguments && arguments.length>0)
		{
			var oSearch	= new Object();
			window.location.search.replace(new RegExp("([^?=&]+)(=([^&]*))?", "g"), function($0, $1, $2, $3){
				oSearch[$1] = $3;
			});
			for(var i=0; i<arguments.length; i++)
			{
				var oQuery = arguments[i].split("=");
				oSearch[oQuery[0]] = oQuery[1];
			}

			var oUrl = window.location.protocol + "//" + window.location.hostname;
			if(window.location.pathname!="")
			{
				oUrl += "";//window.location.pathname.replace(new RegExp("(\/$)|(\/\?$)|(\/default\.aspx$)|(\/default\.aspx\?$)", "g" ), "");
			}

			var oQS = "/?"
			for(var QS in oSearch)
			{
				oQS += QS + "=" + oSearch[QS] + "&";
			}
			return oUrl + oQS;
		}
		else
		{
			return document.URL;
		}
        },
	RedirToUrl:	function(url){
		if($.browser.msie)
		{
			var oLink = $('<a>&nbsp;</a>');
               		oLink.attr("href", url);

	                $("body").append(oLink);
			oLink.bind("click", function(){return true;});
			oLink.get(0).click();
		}
		else
		{
			location.href = url;
		}
	}
   });
})(jQuery);


(function(){
 
    var special = jQuery.event.special,
        uid1 = 'D' + (+new Date()),
        uid2 = 'D' + (+new Date() + 1);
 
    special.scrollstart = {
        setup: function() {
 
            var timer,
                handler =  function(evt) {
 
                    var _self = this,
                        _args = arguments;
 
                    if (timer) {
                        clearTimeout(timer);
                    } else {
                        evt.type = 'scrollstart';
                        jQuery.event.handle.apply(_self, _args);
                    }
 
                    timer = setTimeout( function(){
                        timer = null;
                    }, special.scrollstop.latency);
 
                };
 
            jQuery(this).bind('scroll', handler).data(uid1, handler);
 
        },
        teardown: function(){
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
        }
    };
 
    special.scrollstop = {
        latency: 300,
        setup: function() {
 
            var timer,
                    handler = function(evt) {
 
                    var _self = this,
                        _args = arguments;
 
                    if (timer) {
                        clearTimeout(timer);
                    }
 
                    timer = setTimeout( function(){
 
                        timer = null;
                        evt.type = 'scrollstop';
                        jQuery.event.handle.apply(_self, _args);
 
                    }, special.scrollstop.latency);
 
                };
 
            jQuery(this).bind('scroll', handler).data(uid2, handler);
 
        },
        teardown: function() {
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
        }
    };
 
})();

//********************************************
jQuery.HandleEnter = function(element,callback)
{
	jQuery(element).bind($.browser.mozilla ? 'keypress' : 'keydown', function(event){
		var code=event.charCode || event.keyCode;
		if(code && code == 13) {
  			callback(event.target);
  			event.preventDefault();
		};
	});
};

jQuery.HandleClick = function(element,callback)
{
	jQuery(element).bind('click', function(event){
  		callback(event.target);
  		event.preventDefault();
	});

};
