﻿/// <reference path="jquery.intellisense.js" />  
/// <reference path="jquery-1.3.2_min.js" />

 (function($) 
 {   
     // Assign event to window.onload
    jQuery(window).load(function() {
     
     
        //find all the ul.releases elements on the page
        //loop through them and set the image on them.
         $("ul.releases").each
         (            
                function(){                 
                    
                    $_sliderItem = $("#" + this.id +" li:nth-child(1)");
                    var _text = $($_sliderItem).find("div.moreInfoDiv").html();
                    $("#videoSlide_" + this.id).html(_text);
                    
                    $_img = $_sliderItem.find("img");
          
                    if($_img.is(".VIDEO"))
                    {
                        $_img.attr("src", "http://sas-origin.OnstreamMedia.com/origin/gallupinc/www/images/hpsliderplay.png");
                        
                    }            
                    else if($_img.is(".FLEXCHART"))
                    {                    
                        $_img.attr("src", "http://sas-origin.OnstreamMedia.com/origin/gallupinc/www/images/hpsliderview.png");
                    }
                    else{
                        
                        $_img.attr("src", "http://sas-origin.OnstreamMedia.com/origin/gallupinc/www/images/hpsliderread.png");
                    }
                    
                    SetImageSize($_img);
                    
                    $('img[src$=.png]').ifixpng().iunfixpng().ifixpng(); 
                    
                }        
         
         );
    });     
});
 
///The default action for the previous click anchor
function PreviousClick(senderUl)
{        
         var _val = $(senderUl).css("left");

        var _numItems = $(senderUl + " li").siblings().length;

        //var _liWidth = GetListItemWidth(senderUl + " li");
        var _liWidth = $(senderUl + " li").outerWidth(true);
        
        //need to get the amount of items we want to display in the slider at once and 
        //multiply that by _liWidth        
        var _itemSlide = 4 * parseInt(_liWidth);
        
        //set the value the new leftvalue is going to be.
        var _newLeftVal = parseInt(_val) + parseInt(_liWidth); 
        
        //make sure we dont go passed 0 for the left value in the slide.
        if(_newLeftVal   <= 0)
        {            
            $(senderUl).animate({left:_newLeftVal});
        }
}

///The default action for the next click anchor
function NextClick(senderUl)
{
        var _val = $(senderUl).css("left");
   
        //get how many items are in the list.
        var _numItems = $(senderUl + " li").siblings().length;

        //var _liWidth = GetListItemWidth(senderUl + " li");
        var _liWidth = $(senderUl + " li").outerWidth(true);
        
        //need to get the amount of items we want to display in the slider at once and 
        //multiply that by _liWidth        
        var _itemSlide = 4 * parseInt(_liWidth);
        
        //set the value the new leftvalue is going to be.
        var _newLeftVal = parseInt(_val) - parseInt(_liWidth); 
        
        //if the _newLeftVal is less than the amount of the number of the itmes - the amount we want to show(4)
        // multiplied by the width slide if not hold position.
        if(_newLeftVal *(-1) <= (parseInt(_numItems - 4) * parseInt(_liWidth)))
        {            
            $(senderUl).animate({left:_newLeftVal});
        }

}

function MoreInfo(sender)
{ 
     //assign the senderId of the div li making the call
    var _senderId =   "#" + sender.id;
            
    InactivateButtons(sender);        
    //get the parent
    var _parent = $(sender).parent().get(0); 
    
    //get the all the li's in the parent
    var $child  = $(_parent).children().get(0);
      
    //get the current left position of the _parent element
    var _currentLeft = $(_parent).css("left"); 
    
    //save the current left position for later use
    $(_parent).data("leftValue",_currentLeft);
    
    //set the left position of the ul to 0px
    $(_parent).css({left:"0px"});
             
    //clone the li
    var _clone = $(_senderId).clone(false);
    //set the width to take the whole outerdiv 
    _clone.css("width","446px");    
   
   //set the moreinfordiv to display
    _clone.find("div.moreInfoDiv").css("display", "block");

    _clone.id = sender.id +"_clone"; //set the id on the clone 
    _clone.insertBefore($child);    
    var $close = $("<a><img src='http://www.mixx.com/images/buttons/remove.gif' /></a>");
    $close.bind("click", function(){RemoveMoreInfo(this)});
    _clone.find("div.moreInfoDiv").before($close);

}

function DisplayInfo(sender, channel)
{
    //assign the senderId of the div li making the call
    var _senderId =   "#" + sender.id;
    
    var _text = $(_senderId).find("div.moreInfoDiv").html();

    var $_img = $(_senderId).find("div.i span img"); 
    
    //get the new Video
    $("#videoSlide_" + channel).html(_text);
    
    $_selectedImage = $(_senderId).find("img");
    
    if($_selectedImage.is(".VIDEO"))
    {
        $_selectedImage.attr("src", "http://sas-origin.OnstreamMedia.com/origin/gallupinc/www/images/hpsliderplay.png");

    }            
    else if($_img.is(".FLEXCHART"))
    {                    
        $_selectedImage.attr("src", "http://sas-origin.OnstreamMedia.com/origin/gallupinc/www/images/hpsliderview.png"); 
 
    }
    else{
        
        $_selectedImage.attr("src", "http://sas-origin.OnstreamMedia.com/origin/gallupinc/www/images/hpsliderread.png"); 
    }
    
    SetImageSize($_selectedImage);
    //get all the lis and set the overlay png's
    $(_senderId).siblings().each(
        
        function(){    
            
            $_img = $("#" + this.id).find("img");
            $_img.attr("src", "http://sas-origin.OnstreamMedia.com/origin/gallupinc/www/images/hpslideroverlay.png");
            SetImageSize($_img);
        }
    )
    $('img[src$=.png]').ifixpng().iunfixpng().ifixpng(); 
}

function RemoveMoreInfo(sender)
{ 
   //get the parent ul for this item. One parent up is the li the next is the ul
   var $ul = $(sender).parent().parent();
   
   //set the left position back to the current before the more information div.
   $ul.css({left:$ul.data("leftValue")});
   
   //wipe the sender from the DOM
   $(sender).parent().remove();
   
   //reactivate the buttons
   ActivateButtons($ul);
}

function InactivateButtons(sender)
{
   if( $(sender).parents().hasClass("videoSlide"))
   {
        var $_parent  = $(sender).parents().find("div.videoSlide");
        $_parent.find("a.next").unbind("click");
        $_parent.find("a.previous").unbind("click");
   }
}

function ActivateButtons(sender)
{
   if( $(sender).parents().hasClass("videoSlide"))
   {
        var $_parent  = $(sender).parents().find("div.videoSlide");
        var $_ul =  $_parent.find("ul.releases");
         
        $_parent.find("a.next").bind("click",function(){NextClick("#" + $_ul[0].id);});
        $_parent.find("a.previous").bind("click",function(){PreviousClick("#" + $_ul[0].id);});
   }
}

function SetImageSize(imageToResize)
{
    if(jQuery.browser)
    {
        if(jQuery.browser.version == "6.0")
        {
            imageToResize.height("85");
            imageToResize.width("112");
        }
    }
    else
    {
            imageToResize.height("79");
            imageToResize.width("105");
    }
}

//Homepage Video Player
function Swap(_divid, _sourcemovie, _sourceimage,_sourcekey,_sourcetitle,_localplay,_localpause,_localfullscreen,_localexit,_localopenplayer,_localvolume)
{

if (swfobject.hasFlashPlayerVersion("9.0.18")) 
{      
	var flashvars = {
	FLVsource:_sourcemovie,	
	autoplay:"true",
	jpg:_sourceimage,
	title:_sourcetitle,
	key:_sourcekey,
	side:"None",
	popup:"false",
	play:_localplay,
	pause:_localpause,
	fullscreen:_localfullscreen,
	exitfullscreen:_localexit,
	openplayer:_localopenplayer,
	volume:_localvolume
	};
	var params = {
	allowFullScreen:"true",
	allowScriptAccess:"always",
	wmode: "transparent"
	};

 	swfobject.embedSWF("http://sas-origin.OnstreamMedia.com/origin/gallupinc/www/videoplayer_1.23.swf", "flashPlayer" + _divid, "322", "275", "9.0.47", "http://sas-origin.OnstreamMedia.com/origin/gallupinc/www/playerProductInstall.swf", flashvars, params, {});
}
else 
{  
    $("#flashPlayer" + _divid).append("<a href=\"http://www.adobe.com/go/getflash/\"><img src=\"/assets/flash/NoFlash_01.jpg\" width=\"322\" height=\"275\" border=\"0\" alt=\"Get Flash\" /></a>");

}
    $("#playerImage" + _divid).hide();
    $("#playerControls" + _divid).hide();
}

