var escapekeyEnabled = true;
function openStaticPopup() 
{
	
	$.openPopupLayer
	({
		name: "Print",
		width: 700,
		target: "content",
		success: function()
		{ 
			$('#popupLayer_Print .intro').prepend($('.logo').clone());

			var oContainer = $('#popupLayer_Print .container');

			oContainer .append('<br/>');
			printpop();
			oContainer.append($('#footer').clone());

			initCufon();			

			// Undo cufon on the footer element
			var oFooter = $('#popupLayer_Print #footer strong');
			oFooter.text(oFooter.text());
		}
	});
      
}
function printpop()
{
        $('#popupLayer_Print').prepend('<a onclick="$.closePopupLayer()" href="javascript:void(0);" class="close">close</a>');
	$('#popupLayer_Print .heading').prepend('<a onclick="window.print()" href="javascript:void(0);" class="printpopup">Print this page</a>');
	$('#popupLayer_Print .intro .logo').html('<img src="/images/logo.gif"/>'); 	
	$('#popupLayer_Print .intro .heading h1').empty();	
	$('#popupLayer_Print .intro .heading h1').append($('.intro .heading h1').text());
};

$(document).ready(function () {
    $("a[rel='popImages']").colorbox({ current: "", previous: "", next: "" });
    $("a[rel='MediaImages']").colorbox();
    $(".videoBox").colorbox({ innerWidth: 400, innerHeight: 326, onClosed: stop_player });
    //$(".videoBox").colorbox({innerWidth:400, innerHeight:326});
})


function player_ready(obj) 
{
		$("div#cboxLoadedContent #" + obj['id']).each(function(index)
 		{
			try
			{
				this.sendEvent("PLAY");
			}
			catch (err) { }
		});
};


function stop_player()
{
	$("div#cboxLoadedContent .media-player").each(function(index)
 	{
		try
		{
			this.sendEvent("STOP");
		}
		catch (err) { }
	});
} 


/* Gallery (fade-on-click, auto-fade-left) */
jQuery.fn.gallFade = function(_options){
	// defaults options	
	var _options = jQuery.extend({
		duration: 700,
		autoSlide: 5000
	},_options);

	return this.each(function(){
		var _hold = $(this);
		var _speed = _options.duration;
		var _timer = _options.autoSlide;
		var _wrap = _hold.find('ul.bigimage > li');
		var _el = _hold.find('ul.paging > li');
		var _count = _el.index(_el.filter(':last'));
		var _t;
		var _active = _el.index(_el.filter('.active:eq(0)'));
		if (_active < 0) _active = 0;
		var _last = _active;
		_wrap.css({opacity:0}).eq(_active).css({opacity:1});
		_wrap.removeClass('active').eq(_active).addClass('active');
		_el.removeClass('active').eq(_active).addClass('active');
		function fadeEl(){
			_wrap.eq(_last).animate({
				opacity:0
			}, {queue:false, duration: _speed});
			_wrap.eq(_active).animate({
				opacity:1
			}, {queue:false, duration: _speed});
			_wrap.removeClass('active').eq(_active).addClass('active');
			_el.removeClass('active').eq(_active).addClass('active');			
			_last = _active;
		}
		function runTimer(){
			_t = setInterval(function(){
				_active++;
				if (_active > (_count)) _active = 0;
				fadeEl();
			}, _timer);
		}
		runTimer();
		_el.hover(function(){
			_active = _el.index($(this));
			if(_t) clearTimeout(_t);
			fadeEl();
		}, function(){
			runTimer();
		}).click(function(){
			return false;
		})
	});
}

$(document).ready(function(){
	$('div.gallery-fade').gallFade({
		duration: 700,
		autoSlide: 5000
	});

});

function textClear(textbox) {
    if (textbox.value == textbox.defaultValue) {
        textbox.value = "";
    }
}

function textRestore(textbox) {
    if (textbox.value == "") {
        textbox.value = textbox.defaultValue;
    }
}
function loaderPage() {
    window.onunload = function () { };
    $("#content .content").css("height", $("#content").outerHeight()).show();
    var s = $("#content .content #imgLoading").attr("src");
    setTimeout("$('#content .content #imgLoading').attr('src','"+s+"')", 100);
    return true;
}

function SubmitWrapper(e, submit) {
    if (!e) var e = window.event;
    var keyCode = e.charCode || e.keyCode;
    var origin = e.target || e.srcElement;

    if (origin.tagName == "TEXTAREA" || origin.tagName == "SELECT") {
        return true;
    }

    if (keyCode == 13) {
        var target = $(submit);

        target.click();

        var href = target.attr("href");

        if (href && href != "#") {
            window.location = href;
        }

        e.cancelBubble = true;
        if (e.stopPropagation) {
            e.stopPropagation();
        }
        return false;
    }
}

