﻿/// <reference path="jquery.intellisense.js" />  
/// <reference path="jquery-1.2.6.js" />

 $(document).ready(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", "/assets/images/hpsliderplay.png");
                        
                    }            
                    else if($_img.is(".FLEXCHART"))
                    {                    
                        $_img.attr("src", "/assets/images/hpsliderview.png");
                    }
                    else{
                        
                        $_img.attr("src", "/assets/images/hpsliderread.png");
                    }
                    
                    SetImageSize($_img);
                    
                    $('img[src$=.png]').ifixpng().iunfixpng().ifixpng(); 
                    
                }        
         
         );            

    });//jquery load
     
 });//document ready
 
function GetListItemWidth(listItemName)
{
        //get the width, left and right margins to determine how far to slide.
        var _liWidth = $( listItemName).css("width");
        var _liMarginL = $(listItemName).css("margin-left");
        var _liMarginR = $(listItemName).css("margin-right");
        
        //add all the values together to get the final slide value.
        return parseInt(_liWidth) + parseInt(_liMarginL) + parseInt(_liMarginR);

}

///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");
        
        //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");
        
        //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", "/assets/images/hpsliderplay.png");

    }            
    else if($_img.is(".FLEXCHART"))
    {                    
        $_selectedImage.attr("src", "/assets/images/hpsliderview.png"); 
 
    }
    else{
        
        $_selectedImage.attr("src", "/assets/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", "/assets/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)
{

if (swfobject.hasFlashPlayerVersion("9.0.18")) 
{      
	var flashvars = {
	FLVsource:_sourcemovie,	
	autoplay:"true",
	jpg:_sourceimage,
	key:_sourcekey,
	side:"None"
	};
	var params = {
	allowFullScreen:"true",
	allowScriptAccess:"always",
	wmode: "transparent"
	};

 	swfobject.embedSWF("http://sas-origin.OnstreamMedia.com/origin/gallupinc/www/videoplayer_1.27.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();     

}

/*
 * jQuery ifixpng plugin
 * (previously known as pngfix)
 * Version 2.1  (23/04/2008)
 * @requires jQuery v1.1.3 or above
 *
 * Examples at: http://jquery.khurshid.com
 * Copyright (c) 2007 Kush M.
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
 
 /**
  *
  * @example
  *
  * optional if location of pixel.gif if different to default which is images/pixel.gif
  * $.ifixpng('media/pixel.gif');
  *
  * $('img[src$=.png], #panel').ifixpng();
  *
  * @apply hack to all png images and #panel which icluded png img in its css
  *
  * @name ifixpng
  * @type jQuery
  * @cat Plugins/Image
  * @return jQuery
  * @author jQuery Community
  */
 
(function($) {

	/**
	 * helper variables and function
	 */
	$.ifixpng = function(customPixel) {
		$.ifixpng.pixel = customPixel;
	};
	
	$.ifixpng.getPixel = function() {
		return $.ifixpng.pixel || '/assets/images/pixel.gif';
	};
	
	var hack = {
		ltie7  : $.browser.msie && $.browser.version < 7,
		filter : function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='"+src+"')";
		}
	};
	
	/**
	 * Applies ie png hack to selected dom elements
	 *
	 * $('img[src$=.png]').ifixpng();
	 * @desc apply hack to all images with png extensions
	 *
	 * $('#panel, img[src$=.png]').ifixpng();
	 * @desc apply hack to element #panel and all images with png extensions
	 *
	 * @name ifixpng
	 */
	 
	$.fn.ifixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			// in case rewriting urls
			var base = $('base').attr('href');
			if (base) {
				// remove anything after the last '/'
				base = base.replace(/\/[^\/]+$/,'/');
			}
			if ($$.is('img') || $$.is('input')) { // hack image tags present in dom
				if ($$.attr('src')) {
					if ($$.attr('src').match(/.*\.png([?].*)?$/i)) { // make sure it is png image
						// use source tag value if set 
						var source = (base && $$.attr('src').search(/^(\/|http:)/i)) ? base + $$.attr('src') : $$.attr('src');
						// apply filter
						$$.css({filter:hack.filter(source), width:$$.width(), height:$$.height()})
						  .attr({src:$.ifixpng.getPixel()})
						  .positionFix();
					}
				}
			} else { // hack png css properties present inside css
				var image = $$.css('backgroundImage');
				if (image.match(/^url\(["']?(.*\.png([?].*)?)["']?\)$/i)) {
					image = RegExp.$1;
					image = (base && image.substring(0,1)!='/') ? base + image : image;
					$$.css({backgroundImage:'none', filter:hack.filter(image)})
					  .children().children().positionFix();
				}
			}
		});
	} : function() { return this; };
	
	/**
	 * Removes any png hack that may have been applied previously
	 *
	 * $('img[src$=.png]').iunfixpng();
	 * @desc revert hack on all images with png extensions
	 *
	 * $('#panel, img[src$=.png]').iunfixpng();
	 * @desc revert hack on element #panel and all images with png extensions
	 *
	 * @name iunfixpng
	 */
	 
	$.fn.iunfixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var src = $$.css('filter');
			if (src.match(/src=["']?(.*\.png([?].*)?)["']?/i)) { // get img source from filter
				src = RegExp.$1;
				if ($$.is('img') || $$.is('input')) {
					$$.attr({src:src}).css({filter:''});
				} else {
					$$.css({filter:'', background:'url('+src+')'});
				}
			}
		});
	} : function() { return this; };
	
	/**
	 * positions selected item relatively
	 */
	 
	$.fn.positionFix = function() {
		return this.each(function() {
			var $$ = $(this);
			var position = $$.css('position');
			if (position != 'absolute' && position != 'relative') {
				$$.css({position:'relative'});
			}
		});
	};

})(jQuery);