var animatedtab = true;

function ebay_popup(show) {
	
	var h = getHeight('shopbar');
	var ebay_search = getElem('ebay_search_popup');
	var ebay_search_btn = getElem('ebay_search_popup_btn');

	if (show) {
		pos = getObjCoords(ebay_search_btn);
		pos_frame = getObjCoords(getElem('frame'));
		ebay_search.style.top = (pos.y + h - pos_frame.y - 5) + 'px';
		ebay_search.style.left = (pos.x - pos_frame.x) + 'px';
		//ebay_search.style.top = (pos.y + h) + 'px';
		//ebay_search.style.left = (pos.x) + 'px';
		//ebay_search.style.top = h + 'px';
		//ebay_search.style.left = 0 + 'px';
		ebay_search.style.display = 'block';
		ebay_search.style.zIndex = 10001;
		ebay_search_btn.className = "ebay_search_popup_btn_sel";
	} else {
		ebay_search.style.display = 'none';
		ebay_search_btn.className = "";
	}
}	

// Rotating promos
var rotating_promo_current = 1;
var rotating_promo_total = 0;
var rotating_promo_timer = null;

function rotating_promo_init() {
	rotating_promo_total = $('.rotating-promo-info').length;
	
	$('#rotating-promo').mouseover(function() {clearTimeout(rotating_promo_timer);});
	$('#rotating-promo').mouseleave(function() {rotating_promo_timer = setTimeout('rotating_promo_switch()',3000);});

	$('#rotating-promo-menu ul > li').click(function(e) {
		e.preventDefault();
		
		var obj = $(this);
		var id = obj.attr('id').split('-')[4];
		
		rotating_promo_switch(id);
	});
	
	rotating_promo_switch(1);
	if (rotating_promo_total > 1) {
		rotating_promo_timer = setTimeout('rotating_promo_switch()',6000);
	}
}

function rotating_promo_switch(id) {
	if (id == undefined) {
		if ((++rotating_promo_current) > rotating_promo_total) {
			rotating_promo_current = 1;
		}
		
		rotating_promo_timer = setTimeout('rotating_promo_switch()', 6000);
	}
	else {
		if (rotating_promo_timer != null) {
			clearTimeout(rotating_promo_timer);
			rotating_promo_timer = null;
		}
		
		rotating_promo_current = id;
	}

	id = rotating_promo_current;
	
	var img = $('#rotating-promo-info-image-' + id);
	
	$('#rotating-promo-current-title').html(img.attr('alt'));
	$('#rotating-promo-current-description').html($('#rotating-promo-info-description-' + id).html());
	$('#rotating-promo-link').attr('href', $('#rotating-promo-info-link-' + id).attr('href'));
	
	$('#rotating-promo-menu ul > li').removeClass('selected');
	$('#rotating-promo-menu-item-' + id).addClass('selected');
	
	$('#rotating-promo-image').attr('src', img.attr('src')).attr('alt', img.attr('alt')).hide().fadeIn("slow");
}


// TODO: remove this. needed for front page
function frontpromo() {
	$('#frontpage-promo-images ul > li').css("display","none");
	frontpromo_current = 0;
	frontpage_promo_switch(1);
}

var frontpage_rotateTimeout;
function frontpage_promo_switch(num) {
	if (num == undefined) {
		if ((++frontpromo_current) > frontpromos_number) { frontpromo_current = 1; }
	} else {
		frontpromo_current = num;
	}
	num = frontpromo_current;
	$('#frontpage-promo-caption-title').html(frontpromos_data[num-1]['title']);
	$('#frontpage-promo-caption-desc').html(frontpromos_data[num-1]['desc']);
	$('#frontpage-promo-images ul > li').css("display","none");
	$('#frontpage-promo-img-'+num).fadeIn("slow");
	$('#frontpage-promo-menu ul > li').removeClass();
	$('#frontpage-promo-button-'+num).addClass('selected');
	document.getElementById('frontpage-promo-link').href = frontpromos_data[num-1]['url'];
	if (frontpage_rotateTimeout != undefined) clearTimeout(frontpage_rotateTimeout);
	if (frontpromos_number > 1) frontpage_rotateTimeout = setTimeout('frontpage_promo_switch()',6000);
}

var headernav_drop_delay;
var headernav_drop_close_delay;

function headernav_drop_init() {
	$('.pcw_header_ddactive a').each(function(){
		$(this).bind("mouseenter", function(){
			var thisli = $(this).parent();
			var dropdown = '#'+$(thisli).attr('id')+'_dropdown';
			var button = '#'+$(thisli).attr('id');
			var pos = $(thisli).offset();    
			var eWidth = $(thisli).outerWidth();
			var mWidth = $(dropdown).outerWidth();
			var top = $('#pcw_header_firstrow_links').position().top + $('#pcw_header_firstrow_links').outerHeight() + 17;
			clearTimeout(headernav_drop_close_delay);
			clearTimeout(headernav_drop_delay);
			headernav_drop_delay = setTimeout(function() {
				if ($(dropdown).css('display') != 'block') {
					$('.pcw_header_dropdown').css({ display: 'none' });
					$('#pcw_header_firstrow_links ul li').removeClass('site-header-button-hover');
					$(button).addClass('site-header-button-hover');
					$(dropdown).css( { 
						position: 'absolute',
						zIndex: 5000,
						top: top
					} );
					$(dropdown).hide().slideDown()
				}
			}, 0 );
		}).bind("mouseleave",function(){
			clearTimeout(headernav_drop_close_delay);
			clearTimeout(headernav_drop_delay);
			headernav_drop_close_delay = setTimeout(function() {
				$('.pcw_header_dropdown').css({ display: 'none' });
				$('#pcw_header_firstrow_links ul li').removeClass('site-header-button-hover');
			}, 100); 
		});

		var thisli = $(this).parent();
		var dropdown = '#'+$(thisli).attr('id')+'_dropdown';
		$(dropdown).bind("mouseenter", function(){
			clearTimeout(headernav_drop_close_delay);
		}).bind("mouseleave",function(){
			clearTimeout(headernav_drop_close_delay);
			clearTimeout(headernav_drop_delay);
			headernav_drop_close_delay = setTimeout(function() {
				$('.pcw_header_dropdown').css({ display: 'none' });
				$('#pcw_header_firstrow_links ul li').removeClass('site-header-button-hover');
			}, 300); 
		});
	});
}


