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 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) {
	var url_path = config.regionalFormAction;
	var path_ext = url_path.indexOf('?') == -1 ? '?' : '&';
	
	javascript = javascript || '';
	if (javascript!='') {
		eval(javascript);
	}
	window.location = url_path + path_ext + key + '=' + value;
}

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.ajax({
			type: "POST",
			url: url,
			data: {buyqty : buyqty, products_id : products_id, products_bundle: products_bundle},
			async: false,
			dataType: "xml",
			success: 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) {
	if (buyqty == '-1' && jQuery("#customqty").length) {
		buyqty = jQuery("#customqty").val();
    }

	jQuery.ajax({
		type: "POST",
		url: url,
		data: {buyqty : buyqty , products_bundle : products_bundle, buy_now_qty : buy_now_qty},
		async: false,
		dataType: "xml",
		success: 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 = '';
	var extra_info_char_wow_account = '';	
	
	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();
			extra_info_char_wow_account = jQuery('#extra_info_char_wow_account').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.ajax({
			type: "POST",
			url: url,
			data: {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, "extra_info[char_wow_account]" : extra_info_char_wow_account},
			async: false,
			dataType: "xml",
			success: 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);

function client_height_adjust () {
	if (typeof(window.innerWidth) == 'number') { //not IE
		return 20;
	} else {
		return 59;
	}
}

function forgotPasswordAction() {
	jQuery("#fpContent").css('display','');
	jQuery("#fpLink").css('display','none');
	realign_fancybox("login_table");
}

function forgotPasswordAction_login() {
	jQuery("#fpContent").css('display','');
	jQuery("#fpLink").css('display','none');
	realign_fancybox_login("login_table_login");
}

function set_fancybox_position () {
	var boxTopValue = 0, boxLeftValue = 0;
	//Get the screen height and width
	var docH = jQuery(document).height();
	var winW = jQuery(window).width();
	var winH = jQuery(window).height();
	
	boxTopValue = winH/2 - jQuery('#fancy_content').height()/2 - 30;
	boxLeftValue = winW/2 - 245;
	
	jQuery("#fancy_box").css({'display':'block', 'left':boxLeftValue, 'visibility':'visible', 'top':boxTopValue});
	jQuery("#fancy_box_Bg").css({'display':'block', 'position':'absolute', 'width':winW, 'height':docH, 'visibility':'visible'});
	
	if (typeof(window.innerWidth) == 'number') {
		jQuery("#fancy_box").css({'position':'fixed'});
	}
}

function realign_fancybox (table_id) {
	if(jQuery("#fancy_box").css('display') == 'block') {
		jQuery("#fancy_box").css('height',jQuery("#"+table_id).height()+client_height_adjust());
		
		var boxTopValue = 0, boxLeftValue = 0;
		var docH = jQuery(document).height();
		var winW = jQuery(window).width();
		var winH = jQuery(window).height();
		
		boxTopValue = winH/2 - jQuery('#fancy_content').height()/2 - 30;
		boxLeftValue = winW/2 - 245;
		
		jQuery("#fancy_box").css({'left':boxLeftValue, 'top':boxTopValue});
		jQuery("#fancy_box_Bg").css({'width':winW, 'height':docH});
	}
}

function hideFancyBox() {
	jQuery("#fancy_close").css('display','none');
	jQuery("#fancy_box").css({'display':'none','visibility':'hidden'});
	jQuery("#fancy_box_Bg").css({'display':'none','visibility':'hidden'});
	jQuery("body").css('overflow','');
}

function set_fancybox_position_login () {
	var boxTopValue = 0, boxLeftValue = 0;
	//Get the screen height and width
	var docH = jQuery(document).height();
	var winW = jQuery(window).width();
	var winH = jQuery(window).height();
	
	boxTopValue = winH/2 - jQuery('#fancy_content_login').height()/2 - 30;
	boxLeftValue = winW/2 - 245;
	
	jQuery("#fancy_box_login").css({'display':'block', 'left':boxLeftValue, 'visibility':'visible', 'top':boxTopValue});
	jQuery("#fancy_box_Bg").css({'display':'block', 'position':'absolute', 'width':winW, 'height':docH, 'visibility':'visible'});
	
	if (typeof(window.innerWidth) == 'number') {
		jQuery("#fancy_box_login").css({'position':'fixed'});
	}
}

function realign_fancybox_login (table_id) {
	if(jQuery("#fancy_box_login").css('display') == 'block') {
		jQuery("#fancy_box_login").css('height',jQuery("#"+table_id).height()+client_height_adjust());
		
		var boxTopValue = 0, boxLeftValue = 0;
		var docH = jQuery(document).height();
		var winW = jQuery(window).width();
		var winH = jQuery(window).height();
		
		boxTopValue = winH/2 - jQuery('#fancy_content_login').height()/2 - 30;
		boxLeftValue = winW/2 - 245;
		
		jQuery("#fancy_box_login").css({'left':boxLeftValue, 'top':boxTopValue});
		jQuery("#fancy_box_Bg").css({'width':winW, 'height':docH});
	}
}

function hideFancyBox_login() {
	jQuery("#fancy_box_login").css({'display':'none','visibility':'hidden'});
	jQuery("#fancy_box_Bg").css({'display':'none','visibility':'hidden'});
	jQuery("body").css('overflow','');
}

function generateRegionalContent() {
	var pop_out;
	
	set_fancybox_position();
	
	jQuery.ajax({
		type: "post",
		url: config.generateRegionalBox_ajax_url,
		data: 'regional_action=preload',
		dataType: 'xml',
		beforeSend:  function() {
			pop_out = '<table cellspacing="0" cellpadding="0" width="100%"><tr><td>';
			pop_out += '<table id="regional_table" width="100%" bgcolor="#ffffff" cellspacing="2" cellpadding="10" style="border: 5px solid white">';
			pop_out += '<tr><td align="center"><img src="/images/loading.gif" width="20" height="20"></td></tr>';
			pop_out += '</table>';
			pop_out += '</td></tr></table>';
			
			jQuery("#fancy_content").html(pop_out);
			realign_fancybox("regional_table");
		},
		success: function(xml){
			if(config.cookies_enabled == "1") {jQuery("#fancy_close").css('display','block');}
			pop_out = '<form name="regionalForm" method="post" action="'+config.regionalFormAction+'">';
	  		pop_out += '<table id="regional_table" cellspacing="5" cellpadding="3" width="100%" style="background-color:#ffffff;padding:5px 12px;">';
			pop_out += '<tr><td colspan="2"><b class="largeFont">'+config.regionalTitle+'</b></td></tr>';
			pop_out += '<tr><td class="smallText" colspan="2"><div class="dottedLine" style="padding-top:5px;margin-top:0px;"><!-- --></div></td></tr>';
			pop_out += '<tr><td class="smallText"><font class="largeText"><b>'+config.entryCountry+' </b></font></td>';
			pop_out += '<td><select id="id_country" name="RegionalSet[loc_country]">';
			if (jQuery(xml).find('country').length > 0) {
				jQuery(xml).find("country").each(function(){
					pop_out += '<option value="'+jQuery(this).attr('id')+'" '+jQuery(this).attr('selected')+'>'+jQuery(this).text()+'</option>\n';
				});
			} else {
				pop_out += '<option value="">Not found.</option>';
			}
			pop_out += '</select></td></tr>';
			pop_out += '<tr><td class="smallText"><font class="largeText"><b>'+config.entryCurrency+' </b></font></td>';
			pop_out += '<td><div id="div_currency"></div></td></tr>';
			pop_out += '<tr><td class="smallText" valign="top"><font class="largeText"><b>'+config.entryLanguage+' </b></font></td>';
			pop_out += '<td><div id="div_language"></div></td></tr>';
			pop_out += '<tr><td class="smallText" colspan="2"><div class="dottedLine" style="padding-top:5px;margin-top:0px;"><!-- --></div></td></tr>';
			pop_out += '<tr><td align="right" colspan="2">';
			pop_out += '<div class="green_button_fix_width"><a href="javascript:document.regionalForm.submit();"><span><font>'+config.actionSave+'</font></span></a></div>';
			pop_out += '</td></tr></table></form>';
			
			jQuery("#fancy_content").html(pop_out);
			realign_fancybox("regional_table");
			
			jQuery("#id_country").change(function () {
				jQuery("#div_language, #div_currency").html(config.loadingText);
				realign_fancybox("regional_table");
				
				jQuery.ajax({
					type: "post",
					url: config.generateRegionalBox_ajax_url,
					data: {'regional_action':'getRegionalContent', 'country_ajx':jQuery(this).val()},
					dataType: 'xml',
					success: function(xml){
						pop_out = '<select name="RegionalSet[currency]">';
						if (jQuery(xml).find('currency').length > 0) {
							jQuery(xml).find("currency").each(function(){
								pop_out += '<option value="'+jQuery(this).attr('id')+'" '+jQuery(this).attr('selected')+'>'+jQuery(this).text()+'</option>\n';
							});
						} else {
							pop_out += '<option value="">Not found.</option>';
						}
						pop_out += '</select>';
						
						jQuery("#div_currency").html(pop_out);
						
						pop_out = '';
						if (jQuery(xml).find('language').length > 0) {
							jQuery(xml).find("language").each(function(){
								pop_out += '<input id="'+jQuery(this).attr('id')+'" type="radio" name="RegionalSet[language]" value="'+jQuery(this).attr('id')+'" '+jQuery(this).attr('selected')+'><label for="'+jQuery(this).attr('id')+'">'+jQuery(this).text()+'</label><br>';
							});
						}
						
						jQuery("#div_language").html(pop_out);
						realign_fancybox("regional_table");
					}
				});
			}).change();
		}
	});
}

function generateLoginContent() {
	var pop_out;
	
	set_fancybox_position_login();
	
	realign_fancybox_login("login_table_login");
	
	jQuery("#fancy_close_login").pngfix();
	
	jQuery('div#fancy_content_login #loginContent #entry_email').focus();
	
	jQuery("div#fancy_content_login #loginContent").click(function() {
		jQuery("#act_login").attr('checked', true);
	});
	
	jQuery("#fpContent").click(function() {
		jQuery("#act_password").attr('checked', true);
	});
}

jQuery(window).bind('resize', function() {
	if(jQuery("#fancy_box").css('display') == 'block'){
		set_fancybox_position();
	}
});

jQuery(window).bind('scroll', function() {
	if(jQuery("#fancy_box").css('display') == 'block' && typeof(window.innerWidth) != 'number'){
		var scrollWinH = (jQuery(window).height()/2) - 150 + jQuery(this).scrollTop();	
		jQuery("#fancy_box").css({top:scrollWinH+"px"});
	}
});

jQuery(document).ready(function(){
	jQuery(".bubbleInfo").each(function () {
        var hideDelay = 0;
        var hideDelayTimer = null;
        var beingShown = false;
        var shown = false;
        var trigger = jQuery(".pbubble_trigger", this);
        var alignLeft = (config.language_code == 'en' ? -28 : -10) + jQuery(".pbubble_trigger").width()/2;
    	var info = jQuery(".popupBubble", this).css({'opacity':0, 'top':15, 'left': alignLeft+'px'});
		
        jQuery([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
				beingShown = false;
                shown = true;
                
                info.css({display: 'block', opacity: 1});
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                shown = false;
                info.css({'display':'none', 'opacity':0});
            }, hideDelay);

            return false;
        });
    });
    
    jQuery("#select_link_zones, #error_region_link").bind("click", function(e){
		generateRegionalContent();
    });
    
	jQuery("#fancy_login_box").bind("click", function(e){
		generateLoginContent();
	});
	
	if (config.cookies_enabled == "1") {
		jQuery("#fancy_close").pngfix();
		
		jQuery("#fancy_close").bind("click", function(e){
			hideFancyBox();			
		});
		
		jQuery("div#select_link_zones").mouseover(function(){
			jQuery("div#select_link_zones").css('border', '1px solid #FFF');
		}).mouseout(function(){
			if (typeof(window.innerWidth) == 'number') {
				jQuery("div#select_link_zones").css({'border':'1px solid transparent'});
			} else {
				jQuery("div#select_link_zones").css({'border-color':'pink', 'filter':'chroma(color=pink)'});
			}
			
		});
	} else {
		generateRegionalContent();
	}
});