/*  $Id: CategoryListing.js 1824 2006-11-29 00:47:13Z rreyes $
 * 
 */
var is_out=true;
var is_on;

function initialize(cond)
{
	if(cond){
		$(".pop-up-menu").hide();
	}
	is_out = true;
}

function clearTimer()
{
	clearTimeout(is_on);
}

function get_offset(el,type)
{
    var i = 0;
	var nde = el;
    while (nde != document.body)
    {
         i += (type=='left') ? nde.offsetLeft:nde.offsetTop;
				 nde = nde.offsetParent;
    }
    return i;
}

function menuSetup()
{
	$("div[@id='breadcrumbs-textbox2']")
	.mouseover(function(){
		var pop_text = $(this).find('div').get(0);
		var pop_left = get_offset(pop_text,'left');
		var pop_top	 = get_offset(pop_text,'top');
		
		initialize(true);
		clearTimer();
		var lname = $(this).find('a').get(0).rel;
		
		if(lname){
			$("#category_"+lname)
				.css({
					"top": (pop_top+20) +"px",
					"left":(pop_left-5) +"px"
				})
				.show()
				.mouseover(function(){
					clearTimer();
					$(this).show();
				})
				.mouseout(function(){
					is_out=true;
					$(this).hide();
				});
		}	
	})
	.mouseout(function(){
		is_on = setTimeout('initialize('+is_out+')',500);
	});
}

function navSetup()
{
	$("#listing-sort-listbox").change(function(){
		window.location = listingURL + "&sort="+ this.value;
	});
}
// shipping fee
function shippingInitialize()
{
	$(gshippingFeeId+":visible").hide();
}
var gshippingFeeId;
function shippingFeeSetup(){
	$("span.shipping-fee")
	.hover(function(){
		var pop_text = $(this).find('span').get(0);
		var pop_left = get_offset(pop_text,'left');
		var pop_top	 = get_offset(pop_text,'top');
		var lname = $(this).find('a').get(0).rel;
		if(lname){
			gshippingFeeId = "#shipping-fee_"+lname;
			$(gshippingFeeId)
				.css({
					"top": (pop_top+7) +"px",
					"left":(pop_left-25) +"px"
				})
				.show()
				.hover(function(){
					$(this).show();
				},function(){
					$(this).hide();
				});
		}	
	},function(){
		shippingInitialize();
	});
}

// user details
function userInitialize(cond)
{
	if(cond){
		$(".seller-holder-info").hide();
	}
	is_out = true;
}

function userSetup(){
	$("span[@id='seller-info']")
	.mouseover(function(){
		var pop_text = $(this).find('span').get(0);
		var pop_left = get_offset(pop_text,'left');
		var pop_top	 = get_offset(pop_text,'top');
		shippingInitialize(true);
		clearTimer();
		var lname = $(this).find('a').get(0).rel;
		if(lname){
			$("#seller-holder_"+lname)
				.css({
					"top": (pop_top+17) +"px",
					"left":(pop_left-90) +"px"
				})
				.show()
				.mouseover(function(){
					$(this).show();
				})
				.mouseout(function(){
					is_out=true;
					$(this).hide();
				});
		}	
	})
	.mouseout(function(){
		is_on = setTimeout('userInitialize('+is_out+')',500);
	});
}

// order option
function orderInventoryInitialize(cond)
{
	if(cond){
		$(".order-inventory-pop").hide();
	}
	is_out = true;
}

function orderInventorySetup(){
	$("span[@id='order-inventory']")
	.mouseover(function(){
		var pop_text = $(this).find('span').get(0);
		var pop_left = get_offset(pop_text,'left');
		var pop_top	 = get_offset(pop_text,'top');
		shippingInitialize(true);
		clearTimer();
		var lname = $(this).find('a').get(0).rel;
		if(lname){
			$("#order-inventory-pop_"+lname)
				.css({
					"top": (pop_top+20) +"px",
					"left":(pop_left-105) +"px"
				})
				.show()
				.mouseover(function(){
					$(this).show();
				})
				.mouseout(function(){
					is_out=true;
					$(this).hide();
				});
		}	
	})
	.mouseout(function(){
		is_on = setTimeout('orderInventoryInitialize('+is_out+')',500);
	});
}
// quick search
function onTopQ(id){
	var elmRow = document.getElementById(id);
	elmRow.className='cat-item-row-hover';
}

function onOutQ(id){
	var elmRow = document.getElementById(id);
	elmRow.className='cat-item-row';
}
// category listing
function onTopC(id){
	var elmRow = document.getElementById(id);
	elmRow.className='item-row-hover';
}

function onOutC(id){
	var elmRow = document.getElementById(id);
	elmRow.className='item-row';
}

$(document).ready(function()
{
	menuSetup();
	navSetup();
	shippingFeeSetup();
	userSetup();
	orderInventorySetup();
}) 