
var bkmrkTitl = 'Yad!g.com';
var bkmrkUrl = 'http://www.yadig.com/';


function bookmarksite(){
	if(document.all)// ie
		window.external.AddFavorite(bkmrkUrl, bkmrkTitl);
	else if (window.sidebar) // firefox
		window.sidebar.addPanel(bkmrkTitl, bkmrkUrl, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',bkmrkUrl);
		elem.setAttribute('title',bkmrkTitl);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
}

var gflag = 0;
var to = null;
var prev = 0;
var curID = 0;

function showMenu(m) {
	
	if (prev != 0) tmp = prev.substring(0,4);
	$("#"+tmp).removeClass('hover');
	
	if ($("#"+m).length == 0) {
		return true;
	}
	
	hideMenu(prev);
	prev = m;
	
	$("#"+curID).addClass('hover');
	$("#"+m).slideDown(150);
	
	gflag = 1;
	
}

function hideMenu(m) {

	if ($("#"+m).length == 0) {
		return true;
	}
	
	if (gflag==0) {
		
		$("#"+m).fadeOut(150);
		$("#"+curID).removeClass('hover');		
		clearTimeout(to);
		gflag = 0;
	}
	
}

function hideMenuTimed(m) {
	gflag = 0;
	to = setTimeout(function() {
		hideMenu(m);
	}, 50); 
}



$(document).ready(function(){

	$("a[id^='dl_']").hoverIntent(
	
		function() {
			curID = $(this).attr("id");
			curPos = $(this).position();
			tmp = curID + '_dd';

			$("#"+tmp).css("left", curPos.left+"px");
			showMenu(tmp);
			
		},	
		function() {}	
	);
	
	$("a[id^='dl_']").hover(
	
		function() {},
		
		function() {
			curID = $(this).attr("id");
			tmp = curID + '_dd';
			
			hideMenuTimed(tmp);
		}
	
	);
	
	$(".dd").hover(
	
		function() {					
			tmp = curID + '_dd';
			clearTimeout(to);				
		},
		
		function() {		
			tmp = curID + '_dd';
			hideMenuTimed(tmp);			
		}
	
	);
	
	$('.dd a').click(function() {
							  
		if(curID == "dl_1") {
			$("#dl_1 span").html($(this).html());
			tmp = $("#dl_1").width(); 
			if (tmp >= 100) {
				$("#dl_1 span").css({ width: '100px' });
			} else {
				$("#dl_1").css({ width: 'auto' });
			}
			
			$('#dl_1'+'_dd'+' a').each(function(index) {
				$(this).removeClass('act');
			});
			$(this).addClass('act');
		}
		
	
		
	});
	
	
	$('.review .inpt input').click(function() {
		if ($(this).attr("value") == "Write review...") $(this).attr("value", "");
	});
	
	$(".review .inpt input").blur(function() {
		if ($(this).attr("value") == "") $(this).attr("value", "Write review...");
    }); 
	
	
	$(".tooltip a").hoverIntent(function() {
		$(this).next("em").stop(true, true).animate({opacity: "show", top: "-20"}, "slow");
	}, function() {
		$(this).next("em").animate({opacity: "hide", top: "-40"}, "fast");
	});

	
	/* --- Rating Tooltips --- */
	$(".tooltip2 a").hoverIntent(function() {
		$(this).next("em").css("left", $(this).position().left+"px");
		$(this).next("em").stop(true, true).animate({opacity: "show", top: "-26"}, "slow");
		//$(this).next("em").show();
	}, function() {
		$(this).next("em").css("left", $(this).position().left+"px");
		$(this).next("em").animate({opacity: "hide", top: "-36"}, "fast");
		//$(this).next("em").hide();
	});
	
	
	/* --- Search Field's Price Range --- */
	var selPriceRange;
	
	$("#priceRange a").hover(function() {
		$(this).siblings().removeClass("act");
		$(this).prevAll("a").addClass("hover");
	}, function() {
		$(this).prevAll("a").removeClass("hover");
		restoreRange();
	});
	
	$("#priceRange a").click(function() {
		$("#inptPriceRange").attr("value", $(this).next("em").children().html());
		$(this).addClass("act");
		$(this).prevAll("a").addClass("act");
		selPriceRange = $(this);
	});
	
	function restoreRange() {
		$(selPriceRange).addClass("act");
		$(selPriceRange).prevAll("a").addClass("act");
	}

});
