﻿
$(document).ready(function() {
    $('#obj-videos-item-0').bind("mouseenter", function(){
        $('#obj-videos-flyover-item-0').show("fast");
    });
    $('#obj-videos-flyover-item-0').bind("mouseleave", function(){
        $('#obj-videos-flyover-item-0').hide("fast");
    });
    $('#obj-videos-item-1').bind("mouseenter", function(){
        $('#obj-videos-flyover-item-1').show("fast");
    });
    $('#obj-videos-flyover-item-1').bind("mouseleave", function(){
        $('#obj-videos-flyover-item-1').hide("fast");
    });
    $('#obj-videos-item-2').bind("mouseenter", function(){
        $('#obj-videos-flyover-item-2').show("fast");
    });
    $('#obj-videos-flyover-item-2').bind("mouseleave", function(){
        $('#obj-videos-flyover-item-2').hide("fast");
    });
    $('#obj-videos-item-3').bind("mouseenter", function(){
        $('#obj-videos-flyover-item-3').show("fast");
    });
    $('#obj-videos-flyover-item-3').bind("mouseleave", function(){
        $('#obj-videos-flyover-item-3').hide("fast");
    });
});

//RATINGS
var bHasRated = false;
var xmlHttpObjListing = null;

function flyoverRating(iStars)
{
    if(bHasRated) { return; }
    var obj;
    for(var n=1; n<=5; n++)
    {
        obj = document.getElementById('ratestar'+n);
        if(obj!=null)
        {
            if(n<=iStars)
                obj.src='/images/global/stars/starRatingRed.gif';
            else
                obj.src='/images/global/stars/starRatingGray.gif';
        }
    }
}

function clickRating(iStars, iObjectID)
{
    if(bHasRated) { return; }
    bHasRated = true;

    ajaxRequest("/Script/ajax_callbacks/rate_object.ashx?stars=" + iStars + "&objectid=" + iObjectID, "thanksforrating");
}


//LISTINGS AJAX
var showIfEmpty = true;

function getListingsAJAX(strUrl, showEmptyListings)
{
	showIfEmpty = showEmptyListings;
	xmlHttpObjListing = GetXmlHttpObject(xmlListingsEvent);
	xmlHttpObjLaunch(xmlHttpObjListing, strUrl)
}

function xmlListingsEvent()
{
    if (xmlHttpObjListing.readyState == 4 || xmlHttpObjListing.readyState == "complete")
	{
	    var strText = xmlHttpObjListing.responseText;    
        var elemListings = document.getElementById("listings_ajax");
        if(strText.indexOf("Not airing in the next 14 days") > 0 && !showIfEmpty)
            {
            var outerListingsContainer = document.getElementById("outerListingsContainer");
            outerListingsContainer.style.display = "none";
            }
        else
            elemListings.innerHTML = strText;
	}
}

/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * written by Alen Grakalic (http://cssglobe.com)
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 */
 
this.imagePreview = function(){	
	/* CONFIG */
		xOffset = 10;
		yOffset = 30;
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.name +"' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});