jQuery(document).ready(function(){
	jQuery('#search_field_input').hint();
	jQuery('#filter_field_input').hint();

	jQuery("input:text , input:password").not(jQuery("#filter_field_input")).not(jQuery("#search_field_input")).not(jQuery("#zone_country_filter")).focus( function() { changeOnFocusClass(this); } );
	jQuery("input:text , input:password").not(jQuery("#filter_field_input")).not(jQuery("#search_field_input")).not(jQuery("#zone_country_filter")).blur( function() { changeOnBlurClass(this); } );

	jQuery("#top_50_games_windows_IE").html(jQuery("#top_50_games_window").html());
	jQuery('#top_50_games_windows_IE').hover( show_top_50, hide_top_50 );

	jQuery('#mini_shopping_cart').hover( hover_over_mini_cart, hover_out_mini_cart );
	
	jQuery('#testimonial_scroll div').each(function (i) {
		id = id + 1;
		jQuery(this).Attr('id' , 'testimonial_scroll'+id);
		jQuery(this).hide();
	});
});

var minicart_interval;

function changeOnFocusClass(obj) {
	obj.className = 'inputfocus';
}

function changeOnBlurClass(obj) {
	obj.className = '';
}

function show_mini_cart (show)
{
	if (show == "1") {
		jQuery('#mini_shopping_cart').fadeIn();
		jQuery('#frame2').show();
		jQuery('#checkout_word').html('');
		jQuery('#checkout_link').attr('href','javascript:show_mini_cart()');
		jQuery('#close_cart_icon').show();
	}
	else if (show == "0") {
		jQuery('#frame2').hide();
		jQuery('#mini_shopping_cart').fadeOut();
		jQuery('#checkout_word').html('Checkout');
		jQuery('#checkout_link').attr('href','checkout.php');
		jQuery('#close_cart_icon').hide();
	}
	else {
		if (jQuery('#mini_shopping_cart').css('display') == "none") {
			jQuery('#mini_shopping_cart').fadeIn();
			jQuery('#frame2').show();
			jQuery('#checkout_word').html('');
			jQuery('#checkout_link').attr('href','javascript:show_mini_cart()');
			jQuery('#close_cart_icon').show();
		}
		else {
			jQuery('#mini_shopping_cart').fadeOut();
			jQuery('#frame2').hide();
			jQuery('#checkout_word').html('Checkout');
			jQuery('#checkout_link').attr('href','checkout.php');
			jQuery('#close_cart_icon').hide();
		}
	}
}

function show_top_50 ()
{
	setTimeout("show_top_50_delay()",200);
	jQuery('#top_50_games_flag').val('1');
}

function show_top_50_delay ()
{
	if (jQuery('#top_50_games_window').css('display') == "none" && (jQuery('#top_50_games_flag').val() == "1")) {
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			var left_coordinate = jQuery("#top_50_games_link").offset().left;
			var top_coordinate = jQuery("#top_50_games_link").offset().top;

			jQuery('#top_50_games_windows_IE').css('top',top_coordinate -3 + 'px');
			jQuery('#top_50_games_windows_IE').css('left',left_coordinate - 2 + 'px');
			jQuery('#top_50_games_windows_IE').css('display',"block");
		}
		else {
			jQuery('#top_50_games_window').css('display',"block");
		}
	}
	
	jQuery('#top_50_games_flag').val('1');
}

function hide_top_50 ()
{
	setTimeout("hide_top_50_delay()",300);
	jQuery('#top_50_games_flag').val('0');
}

function hide_top_50_delay ()
{
	if (jQuery('#top_50_games_flag').val() == "0") {
		jQuery('#top_50_games_window').hide();
		jQuery('#top_50_games_windows_IE').hide();
	}
}

function show_zones ()
{
	if (jQuery('#select_box_zones').css('display') == "none") {
		var left_coordinate = jQuery("#select_link_zones").offset().left;
		var top_coordinate = jQuery("#select_link_zones").offset().top;
		var left_coordinate1 = left_coordinate + 5;
		var top_coordinate1 = top_coordinate + 5;

		jQuery('#select_box_zones').css('top',top_coordinate1+'px');
		jQuery('#select_box_zones').css('left',left_coordinate1+'px');

		jQuery('#select_box_zones_background').css('top',top_coordinate+'px');
		jQuery('#select_box_zones_background').css('left',left_coordinate+'px');

		jQuery('#select_box_zones').show();
		jQuery('#select_box_zones_background').show();
	}

	jQuery('#zone_country_filter').focus();
}

function hide_zones ()
{
	if (jQuery('#select_box_zones').css('display') != "none") {
		jQuery('#select_box_zones').hide();
		jQuery('#select_box_zones_background').hide();
	}
}

function show_currencies ()
{
	if (jQuery('#select_box_currencies').css('display') == "none") {
		var left_coordinate = jQuery("#select_link_currencies").offset().left;
		var top_coordinate = jQuery("#select_link_currencies").offset().top;
		var left_coordinate1 = left_coordinate + 5;
		var top_coordinate1 = top_coordinate + 5;

		jQuery('#select_box_currencies').css('top',top_coordinate1+'px');
		jQuery('#select_box_currencies').css('left',left_coordinate1+'px');

		jQuery('#select_box_currencies_background').css('top',top_coordinate+'px');
		jQuery('#select_box_currencies_background').css('left',left_coordinate+'px');

		jQuery('#select_box_currencies').show();
		jQuery('#select_box_currencies_background').show();
	}
}

function hide_currencies ()
{
	if (jQuery('#select_box_currencies').css('display') != "none") {
		jQuery('#select_box_currencies').hide();
		jQuery('#select_box_currencies_background').hide();
	}
}

function tongle_description (id)
{
	var imgCollapse = 'images/icon-collapse.gif';
	var imgExpand = 'images/icon-expand.gif';
	
	if (id == 'ezOptionalInformation')
	{
		var idPanel = '#' + id;
		
		if (jQuery(idPanel + '_icon').hasClass('boxHeaderExpand')) {
			jQuery(idPanel + '_icon').toggleClass('boxHeaderCollapse');
			jQuery(idPanel).toggleClass("ezHidePanel");
		}
		else {
			jQuery(idPanel + '_icon').toggleClass('boxHeaderExpand');
			jQuery(idPanel).toggleClass("ezShowPanel");
		}
	}
	
	else 
	{
		// Animation without short desc
		if (jQuery('#'+id+'_short').text() == "") {
			if (jQuery('#'+id+'_long').css('display') == "none") {
				jQuery('#'+id+'_long').slideDown();
				jQuery('#'+id+'_icon').attr('src', imgCollapse);
			}
			else {
				jQuery('#'+id+'_long').hide();
				jQuery('#'+id+'_icon').attr('src', imgExpand);
			}
		}
	
		// Animation with short desc
		else {
			if (jQuery('#'+id+'_long').css('display') == "none") {
				jQuery('#'+id+'_short').hide(function () {
					jQuery('#'+id+'_long').slideDown();
				});
				jQuery('#'+id+'_icon').attr('src', imgCollapse);
			}
			else {
				jQuery('#'+id+'_long').hide(function () {
					jQuery('#'+id+'_short').slideDown();
				});
				jQuery('#'+id+'_icon').attr('src', imgExpand);
			}
		}		
	}
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}

function disableenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13){
	   return false;
	}
	else
	   return true;
}

function tongle_news (id)
{
	if (jQuery('#'+id+'_long').css('display') == "none") {
		jQuery('#'+id+'_long').slideDown();
		jQuery('#'+id+'_icon').attr('src','/images/icon-collapse.gif');
	}
	else {
		jQuery('#'+id+'_long').slideUp();
		jQuery('#'+id+'_icon').attr('src','/images/icon-expand.gif');
	}
}

function set_localization_value (key , value,javascript) {
	eval(javascript);
	if (key == "loc_country") {
		jQuery("#selected_country").val(value);
		document.localization_select_country.submit();
	}
	else if (key == "currency") {
		jQuery("#selected_currency").val(value);
		document.localization_select_currency.submit();
	}
	else if (key == "language") {
		jQuery("#selected_language").val(value);
		document.localization_select_language.submit();
	}

}

function add_to_shopping_cart_cp (url) {
	var buyqty = jQuery("#buyqty").val();
	var products_id = jQuery("#products_id").val();
	var products_bundle = jQuery("#products_bundle").val();

	var runflag = submitValidate();

	if (runflag == true) {
		jQuery.post(url, {buyqty : buyqty , products_id : products_id, products_bundle: products_bundle} ,function(data){
			jQuery(data).find('result').each(function(){
		        var type = jQuery("type", this).text();
		        
		        if (type == "redirect"){
			        var url = jQuery("url", this).text();
				
					document.location.href = url;
				}
				else {
			        var total_item = jQuery("total_item", this).text();
			        var product_name = jQuery("product_name", this).text();
			        var subtotal = jQuery("subtotal", this).text();
	
					scroll(0,0);
					jQuery("#mini_shopping_cart").fadeIn();
					jQuery("#mini_cart_added_item").html(product_name);
					jQuery("#mini_cart_added_item_bg").html(product_name);
					jQuery("#mini_cart_total b").html(subtotal);
					jQuery("#mini_cart_total_items a font").html(total_item);
					jQuery("#mini_cart_link_total_items a font").html(total_item);
					
					clearInterval(minicart_interval);
					minicart_interval = setInterval("jQuery('#mini_shopping_cart').fadeOut()",6000);
				}
		    });
		});
	}
}

function hover_over_mini_cart () {
	clearInterval(minicart_interval);
}

function hover_out_mini_cart () {
	minicart_interval = setInterval("jQuery('#mini_shopping_cart').fadeOut()",1000);
}

function add_to_shopping_cart (url ,buyqty,products_bundle,buy_now_qty) {
	jQuery.post(url, {buyqty : buyqty , products_bundle : products_bundle, buy_now_qty : buy_now_qty} ,function(data){
		jQuery(data).find('result').each(function(){
	        var type = jQuery("type", this).text();
	        
	        if (type == "redirect"){
		        var url = jQuery("url", this).text();
			
				document.location.href = url;
			}
			else {
		        var total_item = jQuery("total_item", this).text();
		        var product_name = jQuery("product_name", this).text();
		        var subtotal = jQuery("subtotal", this).text();

				scroll(0,0);
				jQuery("#mini_shopping_cart").fadeIn();
				jQuery("#mini_cart_added_item").html(product_name);
				jQuery("#mini_cart_added_item_bg").html(product_name);
				jQuery("#mini_cart_total b").html(subtotal);
				jQuery("#mini_cart_total_items a font").html(total_item);
				jQuery("#mini_cart_link_total_items a font").html(total_item);

				clearInterval(minicart_interval);
				minicart_interval = setInterval("jQuery('#mini_shopping_cart').fadeOut()",6000);
			}
	    });
	});
}

function add_to_shopping_cart_cur (url ,buyqty,products_bundle,buy_now_qty) {
	var runflag = add_to_cart_form_checking();

	var delivery_mode = "";
	var extra_info_char_name = "";
	var extra_info_char_online_hr = "";
	var extra_info_char_online_dur = "";
	var delivery_mode = "";
	var extra_info_char_name = "";
	var extra_info_char_account_name = "";
	var extra_info_char_account_pwd = "";
	var delivery_mode = "";
	var extra_info_char_name = "";

	if (runflag) {
		if (jQuery("#delivery_mode_f2f").attr('checked')){
			delivery_mode = jQuery("#delivery_mode_f2f").val();
			extra_info_char_name = jQuery("#extra_info_char_name").val();
			extra_info_char_online_hr = jQuery("#extra_info_char_online_hr").val();
			extra_info_char_online_dur = jQuery("#extra_info_char_online_dur").val();
		}
		else if (jQuery("#delivery_mode_guya").attr('checked')){
			delivery_mode = jQuery("#delivery_mode_guya").val();

			extra_info_char_name = jQuery("#extra_info_char_name").val();
			extra_info_char_account_name = jQuery("#extra_info_char_account_name").val();
			extra_info_char_account_pwd = jQuery("#extra_info_char_account_pwd").val();
		}
		else if (jQuery("#delivery_mode_mail").attr('checked')) {
			delivery_mode = jQuery("#delivery_mode_mail").val();
			extra_info_char_name = jQuery("#extra_info_char_name").val();
		}

		jQuery.post(url, {buyqty : buyqty , products_bundle : products_bundle, buy_now_qty : buy_now_qty, "extra_info[delivery_mode]" : delivery_mode, "extra_info[char_name]" : extra_info_char_name, "extra_info[char_online_time]" : extra_info_char_online_hr, "extra_info[char_online_dur]" : extra_info_char_online_dur, "extra_info[char_account_name]" : extra_info_char_account_name, "extra_info[char_account_pwd]" : extra_info_char_account_pwd} ,function(data){
			jQuery(data).find('result').each(function(){
		        var type = jQuery("type", this).text();
		        
		        if (type == "redirect"){
			        var url = jQuery("url", this).text();
				
					document.location.href = url;
				}
				else {
			        var total_item = jQuery("total_item", this).text();
			        var product_name = jQuery("product_name", this).text();
			        var subtotal = jQuery("subtotal", this).text();
	
					scroll(0,0);
					jQuery("#mini_shopping_cart").fadeIn();
					jQuery("#mini_cart_added_item").html(product_name);
					jQuery("#mini_cart_added_item_bg").html(product_name);
					jQuery("#mini_cart_total b").html(subtotal);
					jQuery("#mini_cart_total_items a font").html(total_item);
					jQuery("#mini_cart_link_total_items a font").html(total_item);
					
					clearInterval(minicart_interval);
					minicart_interval = setInterval("jQuery('#mini_shopping_cart').fadeOut()",6000);
				}
		    });
		});
		
		hideMe();
	}
}

/**
* hoverIntent is similar to jQuery's built-in "hover" function except that
* instead of firing the onMouseOver event immediately, hoverIntent checks
* to see if the user's mouse has slowed down (beneath the sensitivity
* threshold) before firing the onMouseOver event.
* 
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* hoverIntent is currently available for use in all personal or commercial 
* projects under both MIT and GPL licenses. This means that you can choose 
* the license that best suits your project, and use it accordingly.
* 
* // basic usage (just like .hover) receives onMouseOver and onMouseOut functions
* $("ul li").hoverIntent( showNav , hideNav );
* 
* // advanced usage receives configuration object only
* $("ul li").hoverIntent({
*	sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
*	interval: 100,   // number = milliseconds of polling interval
*	over: showNav,  // function = onMouseOver callback (required)
*	timeout: 0,   // number = milliseconds delay before onMouseOut function call
*	out: hideNav    // function = onMouseOut callback (required)
* });
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($) {
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
})(jQuery);

/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

(function ($) {

$.fn.hint = function (blurClass) {
 if (!blurClass) blurClass = 'blur';

 return this.each(function () {
 // get jQuery instance of 'this'
 var $$ = $(this);

 // get it once since it won't change
 var title = $$.attr('title');

 // only apply logic if the element has the attribute
 if (title) {

 // Note this is a one liner

 // on blur, set value to title attr if text is blank
 $$.blur(function () {
 if ($$.val() == '') {
 $$.val(title).addClass(blurClass);
 }
 })

 // on focus, set value to blank if current value matches title attr
 .focus(function () {
 if ($$.val() == title) {
 $$.val('').removeClass(blurClass);
 }
 })

 // clear the pre-defined text when form is submitted
 .parents('form:first').submit(function () {
 if ($$.val() == title) {
 $$.val('').removeClass(blurClass);
 }
 }).end()

 // now change all inputs to title
 .blur();

 // counteracts the effect of Firefox's autocomplete stripping the blur effect
 if ($.browser.mozilla && !$$.attr('autocomplete')) {
 setTimeout(function () {
 if ($$.val() == title) $$.val('');
 $$.blur();
 }, 10);
 }
 }
 });
};

})(jQuery);

/*
 * jQuery blockUI plugin
 * Version 2.08 (06/11/2008)
 * @requires jQuery v1.2.3 or later
 *
 * Examples at: http://malsup.com/jquery/block/
 * Copyright (c) 2007-2008 M. Alsup
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Thanks to Amir-Hossein Sobhi for some excellent contributions!
 */

;(function($) {

if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.1/.test($.fn.jquery)) {
    alert('blockUI requires jQuery v1.2.3 or later!  You are using v' + $.fn.jquery);
    return;
}

// global $ methods for blocking/unblocking the entire page
$.blockUI   = function(opts) { install(window, opts); };
$.unblockUI = function(opts) { remove(window, opts); };

// plugin method for blocking element content
$.fn.block = function(opts) {
    return this.each(function() {
        if ($.css(this,'position') == 'static')
            this.style.position = 'relative';
        if ($.browser.msie) 
            this.style.zoom = 1; // force 'hasLayout'
        install(this, opts);
    });
};

// plugin method for unblocking element content
$.fn.unblock = function(opts) {
    return this.each(function() {
        remove(this, opts);
    });
};

$.blockUI.version = 2.08; // 2nd generation blocking at no extra cost!

// override these in your code to change the default behavior and style
$.blockUI.defaults = {
    // message displayed when blocking (use null for no message)
    message:  '<h1>Please wait...</h1>',
    
    // styles for the message when blocking; if you wish to disable
    // these and use an external stylesheet then do this in your code:
    // $.blockUI.defaults.css = {};
    css: { 
        padding:        0,
        margin:         0,
        width:          '30%', 
        top:            '40%', 
        left:           '35%', 
        textAlign:      'center', 
        color:          '#000', 
        border:         '3px solid #aaa',
        backgroundColor:'#fff',
        cursor:         'wait'
    },
    
    // styles for the overlay
    overlayCSS:  { 
        backgroundColor:'#000', 
        opacity:        '0.6' 
    },
    
    // z-index for the blocking overlay
    baseZ: 1000,
    
    // set these to true to have the message automatically centered
    centerX: true, // <-- only effects element blocking (page block controlled via css above)
    centerY: true,
    
    // allow body element to be stetched in ie6; this makes blocking look better
    // on "short" pages.  disable if you wish to prevent changes to the body height
    allowBodyStretch: true,
    
    // be default blockUI will supress tab navigation from leaving blocking content;
    constrainTabKey: true,
    
    // fadeOut time in millis; set to 0 to disable fadeout on unblock
    fadeOut:  400,
    
    // if true, focus will be placed in the first available input field when
    // page blocking
    focusInput: true,
    
    // suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)
    applyPlatformOpacityRules: true,
    
    // callback method invoked when unblocking has completed; the callback is
    // passed the element that has been unblocked (which is the window object for page
    // blocks) and the options that were passed to the unblock call:
    //     onUnblock(element, options)
    onUnblock: null
};

// private data and functions follow...

var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent);
var pageBlock = null;
var pageBlockEls = [];

function install(el, opts) {
    var full = (el == window);
    var msg = opts && opts.message !== undefined ? opts.message : undefined;
    opts = $.extend({}, $.blockUI.defaults, opts || {});
    opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});
    var css = $.extend({}, $.blockUI.defaults.css, opts.css || {});
    msg = msg === undefined ? opts.message : msg;

    // remove the current block (if there is one)
    if (full && pageBlock) 
        remove(window, {fadeOut:0}); 
    
    // if an existing element is being used as the blocking content then we capture
    // its current place in the DOM (and current display style) so we can restore
    // it when we unblock
    if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {
        var node = msg.jquery ? msg[0] : msg;
        var data = {};
        $(el).data('blockUI.history', data);
        data.el = node;
        data.parent = node.parentNode;
        data.display = node.style.display;
        data.position = node.style.position;
        data.parent.removeChild(node);
    }
    
    var z = opts.baseZ;
    
    // blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;
    // layer1 is the iframe layer which is used to supress bleed through of underlying content
    // layer2 is the overlay layer which has opacity and a wait cursor
    // layer3 is the message content that is displayed while blocking
    
    var lyr1 = ($.browser.msie) ? $('<iframe class="blockUI" style="z-index:'+ z++ +';border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0" src="javascript:false;"></iframe>')
                                : $('<div class="blockUI" style="display:none"></div>');
    var lyr2 = $('<div class="blockUI" style="z-index:'+ z++ +';cursor:wait;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>');
    var lyr3 = full ? $('<div class="blockUI blockMsg blockPage" style="z-index:'+z+';position:fixed"></div>')
                    : $('<div class="blockUI blockMsg blockElement" style="z-index:'+z+';display:none;position:absolute"></div>');

    // if we have a message, style it
    if (msg) 
        lyr3.css(css);

    // style the overlay
    if (!opts.applyPlatformOpacityRules || !($.browser.mozilla && /Linux/.test(navigator.platform))) 
        lyr2.css(opts.overlayCSS);
    lyr2.css('position', full ? 'fixed' : 'absolute');
    
    // make iframe layer transparent in IE
    if ($.browser.msie) 
        lyr1.css('opacity','0.0');

    $([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);
    
    // ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)
    var expr = $.browser.msie && (!$.boxModel || $('object,embed', full ? null : el).length > 0);
    if (ie6 || expr) {
        // give body 100% height
        if (full && opts.allowBodyStretch && $.boxModel)
            $('html,body').css('height','100%');

        // fix ie6 issue when blocked element has a border width
        if ((ie6 || !$.boxModel) && !full) {
            var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');
            var fixT = t ? '(0 - '+t+')' : 0;
            var fixL = l ? '(0 - '+l+')' : 0;
        }

        // simulate fixed position
        $.each([lyr1,lyr2,lyr3], function(i,o) {
            var s = o[0].style;
            s.position = 'absolute';
            if (i < 2) {
                full ? s.setExpression('height','document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + "px"')
                     : s.setExpression('height','this.parentNode.offsetHeight + "px"');
                full ? s.setExpression('width','jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"')
                     : s.setExpression('width','this.parentNode.offsetWidth + "px"');
                if (fixL) s.setExpression('left', fixL);
                if (fixT) s.setExpression('top', fixT);
            }
            else if (opts.centerY) {
                if (full) s.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');
                s.marginTop = 0;
            }
        });
    }
    
    // show the message
    lyr3.append(msg).show();
    if (msg && (msg.jquery || msg.nodeType))
        $(msg).show();

    // bind key and mouse events
    bind(1, el, opts);
        
    if (full) {
        pageBlock = lyr3[0];
        pageBlockEls = $(':input:enabled:visible',pageBlock);
        if (opts.focusInput)
            setTimeout(focus, 20);
    }
    else
        center(lyr3[0], opts.centerX, opts.centerY);
};

// remove the block
function remove(el, opts) {
    var full = el == window;
    var data = $(el).data('blockUI.history');
    opts = $.extend({}, $.blockUI.defaults, opts || {});
    bind(0, el, opts); // unbind events
    var els = full ? $('body').children().filter('.blockUI') : $('.blockUI', el);
    
    if (full) 
        pageBlock = pageBlockEls = null;

    if (opts.fadeOut) {
        els.fadeOut(opts.fadeOut);
        setTimeout(function() { reset(els,data,opts,el); }, opts.fadeOut);
    }
    else
        reset(els, data, opts, el);
};

// move blocking element back into the DOM where it started
function reset(els,data,opts,el) {
    els.each(function(i,o) {
        // remove via DOM calls so we don't lose event handlers
        if (this.parentNode) 
            this.parentNode.removeChild(this);
    });
    if (data && data.el) {
        data.el.style.display = data.display;
        data.el.style.position = data.position;
        data.parent.appendChild(data.el);
        $(data.el).removeData('blockUI.history');
    }
    if (typeof opts.onUnblock == 'function')
        opts.onUnblock(el,opts);
};

// bind/unbind the handler
function bind(b, el, opts) {
    var full = el == window, $el = $(el);
    
    // don't bother unbinding if there is nothing to unbind
    if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked'))) 
        return;
    if (!full) 
        $el.data('blockUI.isBlocked', b);
        
    // bind anchors and inputs for mouse and key events
    var events = 'mousedown mouseup keydown keypress click';
    b ? $(document).bind(events, opts, handler) : $(document).unbind(events, handler);

// former impl...
//    var $e = $('a,:input');
//    b ? $e.bind(events, opts, handler) : $e.unbind(events, handler);
};

// event handler to suppress keyboard/mouse events when blocking
function handler(e) {
    // allow tab navigation (conditionally)
    if (e.keyCode && e.keyCode == 9) {
        if (pageBlock && e.data.constrainTabKey) {
            var els = pageBlockEls;
            var fwd = !e.shiftKey && e.target == els[els.length-1];
            var back = e.shiftKey && e.target == els[0];
            if (fwd || back) {
                setTimeout(function(){focus(back)},10);
                return false;
            }
        }
    }
    // allow events within the message content
    if ($(e.target).parents('div.blockMsg').length > 0)
        return true;
        
    // allow events for content that is not being blocked
    return $(e.target).parents().children().filter('div.blockUI').length == 0;
};

function focus(back) {
    if (!pageBlockEls) 
        return;
    var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];
    if (e) 
        e.focus();
};

function center(el, x, y) {
    var p = el.parentNode, s = el.style;
    var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');
    var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');
    if (x) s.left = l > 0 ? (l+'px') : '0';
    if (y) s.top  = t > 0 ? (t+'px') : '0';
};

function sz(el, p) { 
    return parseInt($.css(el,p))||0; 
};

})(jQuery);
