$(document).ready(function() {
	$(".hover").hover(function() { //On hover...
//                alert("hover");
		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
                var height = $(this).height(); //Get image url and assign it to 'thumbOver'
//                alert(thumbOver);
//                alert(height);
		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
		$(this).find("a").css({'background' : 'url(' + thumbOver + ') no-repeat 0 -'+height+'px'});
		//Animate the image to 0 opacity (fade it out)
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});
});

$(document).ready(function() {
	$(".hover_btn").hover(function() { //On hover...
//                alert("hover");
                var height = $(this).height(); //Get image url and assign it to 'thumbOver'
//                alert(thumbOver);
//                alert(height);
		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
		$(this).css({'background' : 'url(' + thumbOver + ') no-repeat 0 -'+height+'px'});
		//Animate the image to 0 opacity (fade it out)
		$(this).stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity
		$(this).stop().fadeTo('normal', 1).show();
	});
});

$(document).ready(function(){
    //Tooltips
    $('.tip_trigger').hover(function(){
        tip = $(this).find('.tool_tip');
        tip.fadeIn(); //Show tooltip
    }, function() {
        tip.hide(); //Hide tooltip
    }).mousemove(function(e) {
        var mousex = e.pageX; //Get X coodrinates
        var mousey = e.pageY; //Get Y coordinates
//        alert(mousex+' - '+mousey);
        var tipWidth = tip.width(); //Find width of tooltip
        var tipHeight = tip.height(); //Find height of tooltip
//        alert(tipWidth+' - '+tipHeight);
//        alert($(window).width()+' - '+$(window).height());

        //Distance of element from the right edge of viewport
        var tipVisX = $(window).width() - (mousex + tipWidth);
        //Distance of element from the bottom of viewport
        var tipVisY = $(window).height() - (mousey + tipHeight);

        var tipX = (mousex + tipWidth) - mousex;
        var tipY = (mousey + tipHeight) - mousey;

        if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
            mousex = e.pageX - tipWidth - 20;
        }if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
            mousey = e.pageY - tipHeight - 20;
        }
        //Absolute position the tooltip according to mouse position
        tip.css({'margin-top' : 10, 'left': 40});
    });
});


