itemsPerPage = '12';
itemsPerRow = '4';
currentCategory = "trailers-content";
//currentOrder = "date";
openTopSlide = '';
faderClipId = '';
loadSort = "0"

//default values
contentInfo = [];
contentInfo['trailers-content'] = {"current":"1","total":"1","id":"15","order":"date", "active":"1", "data": "", "playerDiv": "", "playerRow": "", "clip" : ""};
contentInfo["interviews-content"] = {"current":"1","total":"1","id":"6","order":"date", "active":"0", "data": "", "playerDiv": "", "playerRow": "", "clip" : ""};

contentInfo["behind-the-scenes-content"] = {"current":"1","total":"1","id":"7","order":"date", "active":"0", "data": "", "playerDiv": "", "playerRow": "", "clip" : ""};

/* contentInfo["premieres-content"] = {"current":"1","total":"1","id":"12","order":"date", "active":"0", "data": "", "playerDiv": "", "playerRow": "", "clip" : ""};

contentInfo["vault-content"] = {"current":"1","total":"1","id":"p1086","order":"date", "active":"0", "data": "", "playerDiv": "", "playerRow": "", "clip" : ""}; 
*/
contentInfo["random-greatness-content"] = {"current":"1","total":"1","id":"p1217","order":"date", "active":"0", "data": "", "playerDiv": "", "playerRow": "", "clip" : ""};
contentInfo["weekly-10-content"] = {"current":"1","total":"1","id":"p1219","order":"date", "active":"0", "data": "", "playerDiv": "", "playerRow": "", "clip" : ""};
contentInfo["all-content"] = {"current":"1","total":"1","id":"all","order":"date", "active":"0", "data": "", "playerDiv": "", "playerRow": "", "clip" : ""};

$(document).ready( function (){

       // Find all the divs that live with the extras-content div
	// and make sure that first one is the only one shown for now
	var tabContainers = $('div.extras-content > div.tab_content');	
	
	// Find the first div under extras-content div and make it display:block
	//$('div.extras-content').children('div:first').css("display","block"); 

	// setup a Click Event for the Extras Tabs to hide 'em 
	$('div.extras-category ul.tabs a').click(function () {
			tabContainers.hide();
			//tabContainers.filter(this.hash).show();
			$(this.hash).show();
		        var h = this.hash.split('#')[1];


			//update the nav boxes per category and set active
			$('#'+h+'-nav .total-pages').html('<a href="javascript:void(0);">'+contentInfo[h].total+'</a>');
			$('#'+h+'-nav .current-page-box').val(contentInfo[h].current);

			//hide previous nav
			$('#'+currentCategory+'-nav').hide();
				
			$('div.extras-category ul.tabs li').removeClass('active');
			$(this).parent().addClass('active');

                        //close any open movie players
                        for(var c in contentInfo){	
                            if(contentInfo[c].playerDiv)
                                extrasPlayerEffectClose(contentInfo[c].playerDiv, "bottom");
                        }
                        $('.slidePlayerClip').removeClass('active');
			
			//set the new category and display
			currentCategory = h;
			$('#'+h+'-nav').show();
		
			//and make sure thickbox will do its thing
			tb_destroy();
			tb_init();
			return false;
	});

	tb_destroy();
	tb_init();


    $('.content-order a').live('click', function () {
		var order = this.hash.split('#')[1];

		if(order == "date") {
			order = "date";
			$('.content-order li.atz a').removeClass('active');
			$('.content-order li.newest a').addClass('active')
		}
		else {
			order = "title_alpha";
			$('.content-order li.newest a').removeClass('active');
			$('.content-order li.atz a').addClass('active')
		}
		//currentOrder = order;
                $('.loader .indicator').show();
                //get data in correct order
	  for(var b in contentInfo){	
	     (function(b) {
                $('#'+b).empty();
                contentInfo[b].order = order;
		$.getJSON("/ajax/extras/"+contentInfo[b].id+"/"+contentInfo[b].order+"/"+"1"+"/"+"12"+"/", function(data) {
				populateExtrasDivs(data, b, 'posters');
				if(b == currentCategory) {
				        initNav();
                        $('.loader .indicator').hide();
				} 
				bindSliderLinks(b);
			});
                contentInfo[b].current = 1;
                //reset the arrow nav
		$("a","#"+b+'-nav .first-page').addClass("disabled");
		$("a","#"+b+'-nav .prevBtn').addClass("disabled");
	      })(b);
	  }

	return false;
    });
    
    var current_url = document.location.toString();
	if (current_url.match('#')) { // the URL contains an anchor
		var myAnchor = '#' + current_url.split('#')[1];
		// check the anchor against all 
		$('[href="' + myAnchor + '"]').click();
	}

	//for each content info, populate their div and set the variables in the contentInfo array
	for(var b in contentInfo){	
		(function(b) {
			$.getJSON("/ajax/extras/"+contentInfo[b].id+"/"+contentInfo[b].order+"/"+"1"+"/"+"12"+"/", function(data) {
		  		contentInfo[b].total = data.total_pages;
				populateExtrasDivs(data, b, 'posters');
				if(b == currentCategory) {
				    initNav();
                    $('.loader .indicator').hide();
				}
                $('#'+b).ajaxSlider({cat: b});
				bindSliderLinks(b);
			});
		})(b);
	}
   

	function initNav(){
		//set current pages nav
		$('#'+currentCategory+'-nav .total-pages').html('<a href="javascript:void(0);">'+contentInfo[currentCategory].total+'</a>');

		$('#'+currentCategory+'-nav .current-page-box').val(contentInfo[currentCategory].current);	
	
		$('#'+currentCategory+'-nav').show();

		if(contentInfo[currentCategory].order == "date")
			$('.content-order li.newest a').addClass('active');
		else
			$('.content-order li.atz a').addClass('active');

	}

//$('#slideshow-nav a').live('click', showFaderPlayer);
$('a.clipImage').live('click', showFaderPlayer);
$('.extrasSliderClip a').live('click', showTopSlidePlayer);
function bindSliderLinks(div){
	$('#'+div+' .slidePlayerClip a').bind('click', showSlidePlayer);
}
function unbindSliderLinks(){
	$('.slidePlayerClip a').unbind('click', showSlidePlayer);
}

$('.close-player a').live('click', function(){
  	thediv = $(this).parent().attr('id');

  	 if(thediv == 'closebottom'){
		var divId = $(this).parents('.tab_content').attr('id');
        $('#'+currentCategory+' .slidePlayerClip').removeClass('active');
		extrasPlayerEffectClose(contentInfo[divId].playerDiv, "bottom");
   	}
   	else {
        //var div = $(this).parents('#topSliderPlayerContainer');
		extrasPlayerEffectClose(topSlidePlayerContainer, "top");
        $('#topSliderContainer .extrasSliderClip').removeClass('active');
   	}

   	return false;
});

function showFaderPlayer() {

   var newFaderId = $(this).parent(div).find('img').attr('id').replace('img','');  //1234

   if(faderClipId != "") {
      document.getElementById('slide'+faderClipId).stopVideo();
      $('#slide'+faderClipId).hide();
      $('#slideshow-bg .loader .indicator').show();
   }

   faderClipId = newFaderId;
   var div = $('#slide'+faderClipId);
   $('#slideshow').cycle('pause');
   globalSEP(faderClipId, div, "", "fader");
   return false;
}

function showTopSlidePlayer() {
   var div = $(this).parents('#topSliderContainer');
   var id = $(this).attr('item');
   var topSlidePlayer = $('<div id="topSlidePlayer"></div>');

   if(!(openTopSlide)) { //if clicked player isn't open

	        topSlidePlayerContainer = $('<div id="topSlidePlayerContainer" class="slidePlayerContainer"></div>');

	        $(div).after(topSlidePlayerContainer);

   topContentDiv = $('<div id="top-slide-clip-content" class="slide-clip-content"></div>');
                topSlidePlayerContainer.append(topSlidePlayer);
                topSlidePlayerContainer.prepend(topContentDiv);
		
		if (contentInfo[currentCategory].playerDiv != "") {
		  extrasPlayerEffectClose(contentInfo[currentCategory].playerDiv, "bottom");
                  $('#'+currentCategory+' .slidePlayerClip').removeClass('active');
		}

                extrasPlayerEffectOpen(topSlidePlayerContainer);


                openTopSlide = id;

	showExtrasPlayer(id, topSlidePlayer, topContentDiv, "top");
        $('#topSliderContainer .extrasSliderClip').removeClass('active');
        $(this).parents('.extrasSliderClip').addClass('active');
   }
   else if(openTopSlide == id){ //click same clip, close player
	extrasPlayerEffectClose(topSlidePlayerContainer, "top");
        $('#topSliderContainer .extrasSliderClip').removeClass('active');
   }
   else {
        openTopSlide = id;
	showExtrasPlayer(id, topSlidePlayer, topContentDiv, "top");
        $('#topSliderContainer .extrasSliderClip').removeClass('active');
        $(this).parents('.extrasSliderClip').addClass('active');
}

   return false;
}

function showSlidePlayer() {
	var item = $(this).parents('.slidePlayerClip').attr('item');
	var row = item / itemsPerRow;
	row = parseInt(row) + 1;
	var divId = $(this).parents('.tab_content').attr('id');
	var div = $(this).parents('.tab_content');

	if (!(contentInfo[divId].playerDiv) || (contentInfo[divId].playerRow != row)) {
//alert("1");
                //different row
		if ((contentInfo[divId].playerRow != row) && (contentInfo[divId].playerRow)) { 
		  extrasPlayerEffectClose(contentInfo[divId].playerDiv, "bottom");
//alert("2");
		}
//alert("3");

        //first click or new row
	    slidePlayerContainer = $('<div id="slidePlayerContainer'+row+'" class="slidePlayerContainer"></div>');
	    slidePlayer = $('<div id="slidePlayer'+row+'"></div>');

	    var lastItemOnPage = $(div).children().children().children().size()-1; //last item on page
		var lastItemOnRow = (row*itemsPerRow)-1; //whether it exists or not			

		if(lastItemOnRow <= lastItemOnPage) //the item we are trying to append to exists
	    	$('.slidePlayerClip[item='+lastItemOnRow+']', div).after(slidePlayerContainer);
		else
	        $('.slidePlayerClip[item='+lastItemOnPage+']', div).after(slidePlayerContainer);

        slidePlayerContainer.append(slidePlayer);
	    contentDiv = $('<div class="slide-clip-content"></div>');
        slidePlayerContainer.prepend(contentDiv);

		contentInfo[divId].playerDiv = slidePlayerContainer;
	    contentInfo[divId].playerRow = row;
		

        if(openTopSlide != "") {
	    	extrasPlayerEffectClose(topSlidePlayerContainer, "top");
            $('#topSliderContainer .extrasSliderClip').removeClass('active');
        }
        extrasPlayerEffectOpen(slidePlayerContainer);
	    showExtrasPlayer($(this), slidePlayer, contentDiv,"bottom");
		
        $('#'+currentCategory+' .slidePlayerClip').removeClass('active');
        $(this).parents('.slidePlayerClip').addClass('active');
				
	}
        else if((contentInfo[divId].clip == item) && (contentInfo[divId].playerRow == row)){ //click on same clip
//alert("4");
		  extrasPlayerEffectClose(contentInfo[divId].playerDiv, "bottom");
        $('#'+currentCategory+' .slidePlayerClip').removeClass('active');
        }
	else { //click on same row
//alert("5");
	        showExtrasPlayer($(this), slidePlayer, contentDiv,"bottom");
        $('#'+currentCategory+' .slidePlayerClip').removeClass('active');
        $(this).parents('.slidePlayerClip').addClass('active');
	}
	
	contentInfo[divId].clip = item;
	return false;
}

function showExtrasPlayer(item, clipDiv, clipContentDiv, type) {

    if(type == "bottom"){
	var assetID = item.attr('id').replace('clip','');
}
    else {
	var assetID = item;
}

    divID= clipDiv[0].id;
//alert(assetID+' '+divID+' '+clipContentDiv[0].id+' '+type);

   $.getJSON('/ajax/asset/',{'asset_id':assetID, 'type':2},function(data){
clipData = data;
       if(data.success) {
            if (type != 'fader'){
				if(data.movie)
					$(clipContentDiv).html('<div id="close'+type+'" class="close-player"><a href="#"><img src="http://content.epixhd.com/styleassets/closebutton.png" /></a></div><h1>'+data.movie.title+':<br/>'+data.title+'</h1>');
				else
					$(clipContentDiv).html('<div id="close'+type+'" class="close-player"><a href="#"><img src="http://content.epixhd.com/styleassets/closebutton.png" /></a></div><h1>'+data.title+'</h1>');					
				if(data.description) $(clipContentDiv).append('<p>'+data.description+'</p>');
				//if(data.tags) $(clipContentDiv).append('<p>Tags: '+data.tags+'</p>');
				
				if(currentCategory != "random-greatness-content" && currentCategory != "weekly-10-content")
					if(data.movie)
						$(clipContentDiv).append('<h2><a href="'+data.movie.url+'">Go to the movie page</a></h2>');
				
				if ((user_status.loggedin) && (data.movie)) {
					if(data.movie.inwindow){
						movieTagName = data.movie.url.split('.com/')[1];
						$(clipContentDiv).append('<h2><a href="/submit_schedule/'+movieTagName+'">watch with friends</a></h2>');
					}
				} 
            }
			if(data.rating == "R"){ 
				if(user_status.loggedin) y=2; //logged in so can watch
				else y=0; //not logged in, prompt                             
				var x = readCookie('epixAgeRating');
				
				if((x == 1) || (y == 2)) createClipPlayer(data, divID);
				else{
					$('#'+divID).empty().hide();
					
					if(type == "fader"){
						//$('.slideshow-slide').hide();
						$('#mature-gate').prependTo('#slideshow').css({'display':'block','position':'absolute','z-index':'10'});
						$('#slideshow-bg .loader .indicator').hide();
					}	
					else {
						if(type == 'bottom') sliderDiv = $('.slidePlayerContainer');
						else sliderDiv = $('#topSlidePlayerContainer'); 
						$('#mature-gate').appendTo(sliderDiv).show();
					}
					if ((x == 0) || (y == 1)) $('#gatekeeper').show(); //can't watch
					else $('#rating-control').show(); //ask age	
				}
			}
			else {
				$('#'+divID).show();
				$('#mature-gate').hide();
  				createClipPlayer(data, divID);
			}
       }
   });
}

$('#submitDate').live('click',function(){
               // the minumum age you want to allow in 
               var min_age = 18;
   
                // change "age_form" to whatever your form has for a name="..." 
			
                var year = parseInt(document.forms["age_form"]["year"].value);
                var month = parseInt(document.forms["age_form"]["month"].value) - 1;
                var day = parseInt(document.forms["age_form"]["day"].value);
				
				
				//var $('form[name=age_form] select')
                var theirDate = new Date((year + min_age), month, day);
                var today = new Date;
    
                if ( (today.getTime() - theirDate.getTime()) < 0) {
                    //set temp session cookie
                    document.cookie = "epixAgeRating=0";
                    $('#rating-control').fadeOut(function(){$('#gatekeeper').show(); });     
                }
                else {                           
                    setCookie('epixAgeRating',1,365)
                    $('#rating-control').fadeOut(function(){createClipPlayer(clipData, divID); });
                }                
                return false;
});
	
globalSEP = showExtrasPlayer;

function createClipPlayer(data,divID){
	//alert(divID);
	// Pass the movie information
	if(data.movie) {
		var pid = data.movie.id;
		var pname = data.movie.title;
	}
	else {
		var pid = data.id;
		var pname = data.category;
	}
	
	var flash_data = {
	    flashvars: {
			
            content_type:         'videoextra',
            content_subtype:         data.category,
            asset_id:        data.id,
            asset_name:    data.category,
            parent_title_asset_id:     pid,
            parent_title_asset_name:     pname,
            user_mso:       '0',
            user_coupon:       '0',
            anon_user_id:     '0',
			mode:         'solo',
			host:         false,
			jsAPI:        true,
			contentID:    'epix1',
			playlist:     data.smil,
			roomID:       '0',
			username:     '',
			userID:       '',
			token:        '',
                        autoplay:      true
	
		},
		params: {
			id:            divID,
			width:         550,
			height:        375
		}
	};
	setupPlayer(flash_data);
      $('#slideshow-bg .loader .indicator').hide();
}

function autoScroll(div){
   $('html,body').animate({
      scrollTop: ($(div).offset().top-195)
   }, 500);
}

function extrasPlayerEffectOpen(div) {
  div.animate({height: '425px'}, 500, 'easeOutCubic', function() {
      autoScroll(div);
  });
}

function extrasPlayerEffectClose(div, type) {
	$('#mature-gate').appendTo($('#content')).hide();
    if(type == "bottom"){
	var divId = div.parents('.tab_content').attr('id');
	contentInfo[divId].playerDiv = "";
	contentInfo[divId].playerRow = "";
    }
    else
        openTopSlide = "";
    
    div.animate({height: '0px'}, 500, 'jswing', function() {
	 $(this).empty().remove();
    });
return false;
}

	function createList(data,displayType){
		var newLi = '<li>';
		var url_link = '';
	
		if(data.content != ""){
			var i = 0;
			for(var c in data.content){
				clip = data.content[c];	                                       
                if(!clip.image_thumbpath)
					var clipImageUrl = "http://content.epixhd.com/styleassets/fun-facts-default.jpg";
				else
					var clipImageUrl = 'http://content.epixhd.com/webassets' + clip.image_thumbpath;
					
					if(displayType == "posters")
					 newLi += '<div class="slidePlayerClip" item="'+i+'"><div class="slidePlayerClipBg"><a id="clip'+clip.video_id+'" href="javascript:void(0);"><div class="slidePlayerClipImage"><img src="'+clipImageUrl+'" /></div><h3>'+clip.movie_title+'</h3></a><p>'+clip.video_title+'</p></a></div></div>';
						else
					 newLi += '<div class="slidePlayerClip" item="'+i+'"><a href="http://content.epixhd.com/webassets'+clip.video_filepath+'">' + clip.video_title +'</a></div>';
				if(i < 12) i++;
				else i=0;						
			}
		}
		newLi += '</li>';
		return newLi;
	}<!--/createList --> 


	function populateExtrasDivs(data, div, displayType){
               contentInfo[div].data = data;

		var newLi = createList(data,displayType);
		var d = '#'+div;
		$(d).append('<ul>'+newLi+'</ul>');

           /* $('.slidePlayerClip a').wTooltip({content: true, style:{position:"absolute", left:"230px"}, callBefore: function(tooltip, node) {
	        var item = $(node).parent().attr('item');
                var title = contentInfo[currentCategory].data.content[item].movie_title;
                var desc = contentInfo[currentCategory].data.content[item].video_description;
	        $(tooltip).html('<h2>'+title+'</h2><p>'+desc+'</p>');
            }});*/

		//create individual content navigation

var n = $('<div id="'+div+'-nav" class="nav-wrap"><ul><li class="first-page"><a href="javascript:void(0);">First</a></li><li class="prevBtn"><a href="javascript:void(0);">Prev</a></li><li class="current-page"><input type="text" class="current-page-box" maxlength="3" /></li><li>of</li><li class="total-pages"></li><li class="nextBtn"><a href="javascript:void(0);">Next</a></li></ul></div>');
		//$('.extras-content-nav').append(w);
//$(w).append(t);
$('.extras-content-nav').append(n);

		if(contentInfo[div].current == contentInfo[div].total)
                   $("a","#"+div+'-nav .nextBtn').addClass("disabled");
	
	}<!--/populateDivs --> 
	

(function($) {

	$.fn.ajaxSlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 	'Previous',
			nextId: 		'nextBtn',	
			nextText:         'Next',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:	false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 		800,
			auto:		false,
			pause:		2000,
			continuous:	false, 
			numeric: 		false,
			numericId: 	'controls',
		        cat:                  'test'
		}; 

		var options = $.extend(defaults, options);  
		this.each(function() {
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).css('width'); 
			var h = $("li", obj).css('height'); 
                        w = parseInt(w);
                        h = parseInt(h);
			var clickable = true;
			obj.width(w); 
	                //obj.height(h); 
			obj.css("overflow","hidden");
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);
			var category = options.cat;

			if(!options.vertical) $("li", obj).css('float','left');
if(contentInfo[category].current == 1){
$("a","#"+category+"-nav .first-page").addClass("disabled");
$("a","#"+category+"-nav .prevBtn").addClass("disabled");
}

	//next arrow
		$("a", "#"+category+"-nav .nextBtn").click(function (){
			if(clickable) {
                                clickable = false;
			        if(contentInfo[category].current == contentInfo[category].total)
			        	return false;
			        else {
					contentInfo[category].current++;	
					var newPage = contentInfo[category].current;	

					//append new content to ul
                    	updateContent(newPage, contentInfo[category].order, contentInfo[category].id, itemsPerPage, "next");
		                        if(contentInfo[category].playerDiv) 
		                             extrasPlayerEffectClose(contentInfo[category].playerDiv, 'bottom');
					}
			}
		});                                     


			//prev arrow
			$("a", '#'+category+'-nav .prevBtn').click(function(){
			    if(clickable) {
                                clickable = false;
			    	if(contentInfo[category].current == 1){
$("a","#"+category+"-nav .first-page").addClass("disabled");
$("a","#"+category+"-nav .prevBtn").addClass("disabled");
			        	return false;
                                }
			        else {
					contentInfo[category].current--;		
					var newPage = contentInfo[category].current;	

					updateContent(newPage, contentInfo[category].order, contentInfo[category].id, itemsPerPage, "prev");
		                        if(contentInfo[category].playerDiv) 
		                             extrasPlayerEffectClose(contentInfo[category].playerDiv, 'bottom');
				}
                             }
			});

			//first page arrow
			$("a", '#'+category+'-nav .first-page').click(function(){
			    if(clickable) {
                                clickable = false;
			    	 if(contentInfo[category].current == 1)
			         	return false;
			         else {
					contentInfo[category].current = 1;
					var newPage = contentInfo[category].current;
						
					updateContent(newPage, contentInfo[category].order, contentInfo[category].id, itemsPerPage, "first");
		                        if(contentInfo[category].playerDiv) 
		                             extrasPlayerEffectClose(contentInfo[category].playerDiv, 'bottom');
					}
                               }
			});

			//last page link		
			$("a", '#'+category+'-nav .total-pages').live('click', function(){
			    if(clickable) {
                                clickable = false;
			        if(contentInfo[category].current == contentInfo[category].total)
			    		return false;
			        else {		
			        	contentInfo[category].current = contentInfo[category].total;
					var newPage = contentInfo[category].current;	
						
					updateContent(newPage, contentInfo[category].order, contentInfo[category].id, itemsPerPage, "next");
		                        if(contentInfo[category].playerDiv) 
		                             extrasPlayerEffectClose(contentInfo[category].playerDiv, 'bottom');
					}	
                                }			
			});

            $('#'+category+'-nav input.current-page-box').keydown(function(event) {
			totalPages = contentInfo[category].total;
			currentPage = contentInfo[category].current; 
			if(event.keyCode == 13){
              		     //capture the input value
              		     var v = $(this).val();

             		     //if v is a valid input
              		     if(v > 0 && v <= totalPages){

						//is the page before or after the current page, prepend/append, and reuse code
					  	if(v < currentPage){
						contentInfo[category].current = v;
						updateContent(v, contentInfo[category].order, contentInfo[category].id, itemsPerPage, "prev");
						}
					  	else if(v > currentPage){
						contentInfo[category].current = v;
						updateContent(v, contentInfo[category].order, contentInfo[category].id, itemsPerPage, "next");
					  	}
					  	else
						   return false; //on the current page
					}
					else if(v > totalPages)  {
						contentInfo[category].current = totalPages = contentInfo[category].total;
						updateContent(contentInfo[category].current, contentInfo[category].order, contentInfo[category].id, itemsPerPage, "next");
					}
					else  {
						contentInfo[category].current = 1;
						updateContent("1", contentInfo[category].order, contentInfo[category].id, itemsPerPage, "prev");
					}
		                        if(contentInfo[category].playerDiv) 
		                             extrasPlayerEffectClose(contentInfo[category].playerDiv, 'bottom');
				}
	});
			
	function updateContent(goToPage, orderBy, id, itemsPerPage, direction){
		
//alert('gotopage: '+goToPage+' | order: '+orderBy+' | id: '+id+' | itemsperpage: '+itemsPerPage+' | direction: '+direction);

		$.getJSON("/ajax/extras/"+id+"/"+orderBy+"/"+goToPage+"/"+itemsPerPage+"/", function(data) {
			var newLi = createList(data,"posters");
			if(direction == 'next') 
				$("ul", obj).append(newLi);
			else {
				$("ul", obj).prepend(newLi);
				//adjust margin
				$("ul", obj).css("margin-left",(w*-1));
			}
			
			//update width of ul
			$("ul", obj).css('width',(s+1)*w);

			//animate the slide
			animate(direction,true);
			$('#'+category+'-nav .current-page-box').val(goToPage);	    


       /*    $('.slidePlayerClip a').wTooltip({content: true, style:{position:"absolute", left:"230px"}, callBefore: function(tooltip, node) {
	        var item = $(node).parent().attr('item');
                var title = contentInfo[currentCategory].data.content[item].movie_title;
                var desc = contentInfo[currentCategory].data.content[item].video_description;
	        $(tooltip).html('<h2>'+title+'</h2><p>'+desc+'</p>');
            }});*/
																							 
		});
	
}
						
			function setCurrent(i){
				i = parseInt(i)+1;
				$("li", "#" + options.numericId).removeClass("current");
				$("li#" + options.numericId + i).addClass("current");
			};
			
			function adjust(){
				if(t>0) {
				    //delete first li
				    $("ul li:first-child", obj).remove();
				}
				else if(t<0) {
				    //delete last li
				    $("ul li:last-child", obj).remove();
				}
				t=0;	
					
				//resize ul
				$("ul", obj).css('width',(s)*w);					
					
				//reset margin-left
				$("ul",obj).css("margin-left",(t*w*-1));
				
				clickable = true;
				bindSliderLinks(currentCategory);
				if(options.numeric) setCurrent(t);
			};
			
			function animate(dir,clicked){
					var ot = t;	
					switch(dir){
						case "next":
							t++;	
						        p = (t*w*-1);	
							break; 
						case "prev":
							t--;
						        p = 0;	
							break; 
						case "first":
							t--;
						        p = 0;
							break; 
						case "last":
							t++;
						        p = (t*w*-1);	
							break; 
						default:
							t = parseint(dir);
							break; 
					};	
					var diff = Math.abs(ot-t);
					var speed = diff*options.speed;
						//p = (t*w*-1);
//alert(t+' '+p);
						unbindSliderLinks();
						$("ul",obj).animate(
							{ marginLeft: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);				
										
					if(!options.continuous && options.controlsFade){
				totalPages = contentInfo[category].total;
				currentPage = contentInfo[category].current;					
						if(currentPage == totalPages){
							$("a","#"+category+'-nav .nextBtn').addClass("disabled");
							//$("a","#"+options.firstId).removeClass("disabled");
							//$("a","#"+options.prevId).removeClass("disabled");
							//$("a","#"+options.lastId).hide();
						} else {
							$("a","#"+category+'-nav .nextBtn').removeClass("disabled");
							//$("a","#"+options.lastId).show();					
						};

						if(currentPage == 1){
							$("a","#"+category+'-nav .first-page').addClass("disabled");
							$("a","#"+category+'-nav .prevBtn').addClass("disabled");
							//$("a","#"+options.firstId).hide();
						} else {
							$("a","#"+category+'-nav .first-page').removeClass("disabled");
							$("a","#"+category+'-nav .prevBtn').removeClass("disabled");
							//$("a","#"+options.firstId).show();
						};					
					};		
					
					if(clicked) clearTimeout(timeout);
					if(options.auto && dir=="next" && !clicked){;
						timeout = setTimeout(function(){
							animate("next",false);
						},diff*options.speed+options.pause);
					};
				
				
			};
			// init
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};		
			
			if(options.numeric) setCurrent(0);
		
			if(!options.continuous && options.controlsFade){					
				//$("a","#"+options.prevId).hide();
				//$("a","#"+options.firstId).hide();				
			};
		});	  
	};

})(jQuery);
                         
		$("#topSliderContainer .slider").easySlider({
            controlsBefore: '<div class="topSliderNav">',
            controlsAfter: '</div>',
            nextId: 's-nextBtn',
            prevId: 's-prevBtn',
            numeric: true,
            numericId: 'singlecontrols',
            continuous: true
        }); 
		
		$('#slideshow').cycle({ 
		  fx:     'fade', 
		  delay:  -1000,
		  timeout: 5000,
		  pager:  '#slideshow-nav', 
		  next:   '#slideshow-next', 
		  prev:   '#slideshow-prev',
		  width: 560, 
		  height: 338,
		  pagerAnchorBuilder:hideLinks
		});
		
		function hideLinks (idx, slide) {
			return '';
		}

/*
		$('#slideshow').before('<div id="slideshow-nav">').cycle({ 
		  fx:     'fade', 
		  delay:  -1000,
		  timeout: 5000,
		  pager:  '#slideshow-nav', 
		  next:   '#slideshow-next', 
		  prev:   '#slideshow-prev',
		  width: 810, 
		  height: 350,
		  pagerAnchorBuilder:imgNav,    
                  cleartype:  true,
                  cleartypeNoBg:  true,
                  before: loadTitles
		});
		*/
/*
      function loadFader(zeroBasedSlideIndex, slideElement){
          var id = $(slideElement).children(div).find('img').attr('id').replace('clip','');  //1234
          var div = $('#slide'+id);
$('#slideshow').cycle('pause');
          globalSEP(id, div, "", "fader");

      }


      function loadTitles (idx, slide){
            var hdr = $(slide).children('.slideshow-caption').children('h1');
if(hdr.val() == ""){
            var assetID = $(hdr).attr('class').replace('clip','');
            $.getJSON('/ajax/asset/',{'asset_id':assetID, 'type':2},function(data){
                if(data.success) {
                   $(hdr).html(data.movie.title);
                }
            });
}
      }

      function imgNav(idx, slide) {
         var src = $(slide).find('img').attr('src');
         var title = $(slide).find('img').attr('title');
         var alt = $(slide).find('img').attr('alt');
         var id = $(slide).find('img').attr('id');
         return '<li><a href="#"><img src="' + src + '" id="'+id+'" alt="'+alt+'" title="'+title+'" /></a></li>';
      };   
           
$(".slideshow-image img").reflect({height:.2,opacity:.3});
*/
});
