﻿var needResize = false;
var isIe6 = $.browser.msie&&$.browser.version=="6.0";
var isIe = jQuery.browser.msie;

var navArrowSlider = function(navWrap, navElementsArray, activeID, arrowY, leftOffset) {

	jQuery(navElementsArray).each(function(){  
		jQuery(this).mouseover(function() { 
			var thisPos = jQuery(this).position().left  + Math.round(jQuery(this).width() / 2 ) - leftOffset;
			jQuery(navWrap).css('background-position', thisPos + 'px ' + arrowY + 'px'); 
		});
	});
	var activePos = jQuery(activeID).position().left  +  Math.round(jQuery(activeID).width() / 2 ) - leftOffset;
	jQuery(navWrap).css({"background": "transparent url('http://img.eryiju.com.cn/img/whole_new/arrow.gif') no-repeat", 'background-position': activePos + 'px ' + arrowY + 'px'});       
	
};


/*   This is to solve the z-index bug of ie
	bug description:
	When there's a relative element or more after the given z-index element( we call it "ze" ), then ze will not apear over the element(s) but under it(them).
*/
/*start of function ie_apply_zindex()*/
var iaz_preserved_elements = [];
var iaz_preserved_zindexes = [];

function ie_apply_zindex(element_id, zindex, context_id) {
	/*	Parameters
	    * the ID of the z-indexed element
	    * the z-index value
	    * optionally, the ID of the block within whose context we’re concerned about this element getting its rightful z-indexed stacking order (defaults to the entire document)
	*/

	// default values
	if (undefined == zindex)
		zindex = 1;
	var context = (undefined == context_id ? $(context_id) : $(document.body));
	var element = $(element_id);
	
	// undo past ie_apply_zindex()
	for (i = iaz_preserved_elements.length-1; i >= 0; i--) {
		iaz_preserved_elements[i].css({'z-index': iaz_preserved_zindexes[i]});
	}
	iaz_preserved_elements = [];
	iaz_preserved_zindexes = [];
	
	// find relative-positioned ancestors of element within context
	element.parents().each( function() {
		var ancestor = $(this);
		if ('relative' == ancestor.css('position')) {
			// preserve ancestor's current z-index
			iaz_preserved_elements.push(ancestor);
			iaz_preserved_zindexes.push( ancestor.css('z-index') );
		
			// apply z-index to ancestor
			ancestor.css('z-index', zindex);
		}
		if (ancestor == context) { throw $break; }
	});
}
/*end of function ie_apply_zindex()*/
function showLogo(logoId){
	jQuery('#'+logoId).css("display","block");
}

function hideLogo(logoId){
	jQuery('#'+logoId).css("display","none");
}

function showSelectCity(){
	jQuery('#citySelector').css("display","block");
}

function hideSelectCity(){
	jQuery('#citySelector').css("display","none");
}

function selectCity(cityId){
	var url = "/store/utils/selectCity.html";
	jQuery.post(url, {'primaryCity.id': cityId}, function(xml) {	
		 
		window.location.reload();
	});
}

function initCart(){
	var cart = $('#cart');
	var cart_expand = $('#cart_expand');
	//var oriheight = cart_expand.getCoordinates().height;
	var cart_open = false;
	var oriheight = cart_expand.height();
	
	cart_expand.css({
		'opacity': 0,
		'display': 'block',
		'height': '0px',
		'background-color': '#F9FAF4'
	});
	/*cart_expand.css({
		'height': Math.round(oriheight * 0.75 ) + 'px'
	});*/
	
	
	
	ie_apply_zindex('#cart_expand',1);

	cart.click(function(){
		if( !cart_open ){
			ie_apply_zindex('#cart_expand',100);
			cart_expand.css({'display': 'block', "z-index" : "100"});
			cart_expand.animate({ 
					'height': oriheight + 'px',
					'opacity': 0.9
			      }, 800 );
			cart_open = true;
		} else
		{
			$('#cart_expand_close').click();
			cart_open = false;
		}
	});
	$('#cart_expand_close').click(function(){
		cart_expand.animate({ 
			'opacity': 0,
			'height': '0px'
		}, 800, "swing", function()
			{
				ie_apply_zindex('#cart_expand',1);
				cart_expand.css({"display": "none", "z-index": "1"});
			});
		cart_open = false;
	});
	
	$('#cart_expand').hide();
}
function viewCart(){
	
	var url = "/store/transact/ajaxViewCart.html";
	
	jQuery.post(url,function(data) {	
		 jQuery("#viewCartId").html(data);
	},"html");
}

function viewUser(){
	var url = "/store/viewUser.html";
	
	jQuery.post(url,function(data) {	
		 jQuery("#currentUser").html(data);
	},"html");
}

/**
* @param number
* @param length  小数点后几位
* @return
*/
function formatNumber(number, length)
{
	if (typeof length == "undefined")
		length = 2;
	var n = Math.pow(10, length);

	return Math.round(number * n) / n;
}

function gotoPage(formName,currentPage){
	var searchForm = document.forms[formName];
//	searchForm["page.currentPage"].value = currentPage;
	var nowPage = document.getElementById("currentPage");
	nowPage.value = currentPage;
	searchForm.submit();
}
function gotoPage2(formName){
	var searchForm = document.forms[formName];
	searchForm.submit();
}


