﻿var appPath = "http://www.supergoodmovies.com/";
function like(vd,gi,ch)
        {
            window.location=appPath+"gallery-index/"+gi+"/"+ch+"/"+vd;
        }
function LengthLimit(Object,maxlimit)
{
    if (Object.value.length > maxlimit)
        Object.value = Object.value.substring(0, maxlimit);        
   
} 
function GetTopItems(ID)
{    
    if (ID=="")
    {           
        document.getElementById("result").innerHTML="Could not load search results.";      
        return;
    }
    
    //document.getElementById("result").innerHTML="<span class='error_text'>Loading...</span><img src='/SuperGoodMovies/images/ajax-loader.gif' />";
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    } 
    
    //var url="http://192.168.1.102/sgm/Home/TopItems/" + ID;
    var url=appPath+"Home/TopItems/" + ID;
        
    xmlHttp.onreadystatechange=resultsGetTopItems;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);    
}

function resultsGetTopItems() 
{ 
    if (xmlHttp.readyState==4)
    { 
        document.getElementById("result").innerHTML=xmlHttp.responseText;
    }
}
 
    function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
    
    function LoadPreData()
    {
       GetTopItems(1);
    }
    
    
    function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function GetNewsResults(str)
{


   if (str.length==0)
    {   
        document.getElementById("InformationGrid").innerHTML="Could not load search results.";
        return;
    }

if(document.getElementById("topPager")!=null)
        {
         document.getElementById("News").style.display ="";
         document.getElementById("topPager").style.display ="none";
         } 
         if(document.getElementById("bottomPager")!=null)
        {
        document.getElementById("bottomPager").style.display ="none";
         document.getElementById("Newsbottom").style.display ="";
        }
        
 

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    } 
  
    var url=appPath+"home/InformationGrid?" + str;
  
    xmlHttp.onreadystatechange=InformationGridChanged;
    
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 

function InformationGridChanged() 
{ 
   if (xmlHttp.readyState==4)
    { 
        document.getElementById("InformationGrid").innerHTML=xmlHttp.responseText;
        if(document.getElementById("topPager")!=null)
        {
        document.getElementById("topPager").style.display ="";
        }
         if(document.getElementById("bottomPager")!=null)
        {
        document.getElementById("bottomPager").style.display ="";
        }
    }
}
function GetInformationComments(str)
{

   if (str.length==0)
    {   
        document.getElementById("InformationGrid").innerHTML="Could not load search results.";
        return;
    }

        if(document.getElementById("topPager")!=null)
        {
         document.getElementById("News").style.display ="";
         document.getElementById("topPager").style.display ="none";
         } 
         if(document.getElementById("bottomPager")!=null)
        {
        document.getElementById("bottomPager").style.display ="none";
         document.getElementById("Newsbottom").style.display ="";
        }
        
 

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    } 
  
    var url=appPath+"home/InformationComments?" + str;
  
    xmlHttp.onreadystatechange=InformationGridChanged;
    
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 

function InformationGridChanged() 
{ 
   if (xmlHttp.readyState==4)
    { 
        document.getElementById("InformationGrid").innerHTML=xmlHttp.responseText;
        if(document.getElementById("topPager")!=null)
        {
        document.getElementById("topPager").style.display ="";
        }
         if(document.getElementById("bottomPager")!=null)
        {
        document.getElementById("bottomPager").style.display ="";
        }
    }
}
function GetInformationImages(str)
{

   if (str.length==0)
    {   
        document.getElementById("InformationImages").innerHTML="Could not load search results.";
        return;
    }

        if(document.getElementById("topPager")!=null)
        {
         document.getElementById("News").style.display ="";
         document.getElementById("topPager").style.display ="none";
         } 
         if(document.getElementById("bottomPager")!=null)
        {
        document.getElementById("bottomPager").style.display ="none";
         document.getElementById("Newsbottom").style.display ="";
        }
        
 

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    } 
  
    var url=appPath+"home/InformationImages?" + str;
  
    xmlHttp.onreadystatechange=InformationImages;
    
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 

function InformationImages() 
{ 
   if (xmlHttp.readyState==4)
    { 
        document.getElementById("InformationImages").innerHTML=xmlHttp.responseText;
        if(document.getElementById("topPager")!=null)
        {
        document.getElementById("topPager").style.display ="";
        }
         if(document.getElementById("bottomPager")!=null)
        {
        document.getElementById("bottomPager").style.display ="";
        }
    }
}

function GetGalleryImages(str)
{

   if (str.length==0)
    {   
        document.getElementById("GalleryImages").innerHTML="Could not load search results.";
        return;
    }

        if(document.getElementById("topPager")!=null)
        {
         document.getElementById("News").style.display ="";
         document.getElementById("topPager").style.display ="none";
         } 
         if(document.getElementById("bottomPager")!=null)
        {
        document.getElementById("bottomPager").style.display ="none";
         document.getElementById("Newsbottom").style.display ="";
        }
        
 

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    } 

    var url=appPath+"home/GalleryImages?" + str;
 
    xmlHttp.onreadystatechange=GalleryImages;
    
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 

function GalleryImages() 
{ 
   if (xmlHttp.readyState==4)
    { 
        document.getElementById("GalleryImages").innerHTML=xmlHttp.responseText;
        if(document.getElementById("topPager")!=null)
        {
        document.getElementById("topPager").style.display ="";
        }
         if(document.getElementById("bottomPager")!=null)
        {
        document.getElementById("bottomPager").style.display ="";
        }
    }
}


    function LoadPreData()
    {
       GetTopItems(1);
    }
    
    
    //For Slide
$(document).ready(function() {	

	//Show Banner
	$(".main_image .desc").show(); //Show Banner
	$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity

	//Click and Hover events for thumbnail list
	$(".image_thumb ul li:first").addClass('active'); 
	$(".image_thumb ul li").click(function(){ 
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
		var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	
		
		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
			//Animate the Teaser				
			$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
				$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
				$(".main_image img").attr({ src: imgTitle , alt: imgAlt});
			});
		}
		
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;
		
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});
			
	//Toggle Teaser
	$("a.collapse").click(function(){
		$(".main_image .block").slideToggle();
		$("a.collapse").toggleClass("show");
	});
	
});//Close Function


//Rating                          
  $(document).ready(function() {
        $(".rating_star_div").each(function(i) {
            
            var hdnField = $(this).find(".explanation >input:hidden");
            var ratingLabel = $(this).find(".ratingLabel");
            var ratingCap = $(this).find(".rating");
            ratingLabel.hide();
            ratingCap.show();
            $(this).find(".question").stars({
            captionEl: $(this).find(".caption")});
              
            $(this).find(".question").click(function() {
                var instance = $(this).data("stars");
                $(this).find(".caption");
                hdnField.val(instance.options.value);
                
                $.get(appPath+"Home/AjaxHtml", getName(), updateResult, "html");
                 function getName() {  
                 return { Rating:(instance.options.value),MovieID:($("#MovieID").val())};  }  
                 function updateResult(html) {
                if(Rating!=0){ this.options.disabled = true;};}});
        });
     });
     

