jQuery.fn.selectbox=function(options){var settings={className:'jquery-selectbox',animationSpeed:"normal",listboxMaxSize:10,replaceInvisible:false};var commonClass='jquery-custom-selectboxes-replaced';var listOpen=false;var showList=function(listObj){var selectbox=listObj.parents('.'+settings.className+'');listObj.slideDown(settings.animationSpeed,function(){listOpen=true;});selectbox.addClass('selecthover');jQuery(document).bind('click',onBlurList);return listObj;}
var hideList=function(listObj){var selectbox=listObj.parents('.'+settings.className+'');listObj.slideUp(settings.animationSpeed,function(){listOpen=false;jQuery(this).parents('.'+settings.className+'').removeClass('selecthover');});jQuery(document).unbind('click',onBlurList);return listObj;}
var onBlurList=function(e){var trgt=e.target;var currentListElements=jQuery('.'+settings.className+'-list:visible').parent().find('*').andSelf();if(jQuery.inArray(trgt,currentListElements)<0&&listOpen){hideList(jQuery('.'+commonClass+'-list'));}
return false;}
settings=jQuery.extend(settings,options||{});return this.each(function(){var _this=jQuery(this);if(_this.filter(':visible').length==0&&!settings.replaceInvisible)
return;var replacement=jQuery('<div class="'+settings.className+' '+commonClass+'">'+'<div class="'+settings.className+'-moreButton" />'+'<div class="'+settings.className+'-list '+commonClass+'-list" />'+'<span class="'+settings.className+'-currentItem" />'+'</div>');jQuery('option',_this).each(function(k,v){var v=jQuery(v);var listElement=jQuery('<span class="'+settings.className+'-item value-'+v.val()+' item-'+k+'">'+v.text()+'</span>');listElement.click(function(){var thisListElement=jQuery(this);var thisReplacment=thisListElement.parents('.'+settings.className);var thisIndex=thisListElement[0].className.split(' ');for(k1 in thisIndex){if(/^item-[0-9]+$/.test(thisIndex[k1])){thisIndex=parseInt(thisIndex[k1].replace('item-',''),10);break;}};var thisValue=thisListElement[0].className.split(' ');for(k1 in thisValue){if(/^value-.+$/.test(thisValue[k1])){thisValue=thisValue[k1].replace('value-','');break;}};thisReplacment.find('.'+settings.className+'-currentItem').text(thisListElement.text());thisReplacment.find('select').val(thisValue).triggerHandler('change');var thisSublist=thisReplacment.find('.'+settings.className+'-list');if(thisSublist.filter(":visible").length>0){hideList(thisSublist);}else{showList(thisSublist);}}).bind('mouseenter',function(){jQuery(this).addClass('listelementhover');}).bind('mouseleave',function(){jQuery(this).removeClass('listelementhover');});jQuery('.'+settings.className+'-list',replacement).append(listElement);if(v.filter(':selected').length>0){jQuery('.'+settings.className+'-currentItem',replacement).text(v.text());}});replacement.find('.'+settings.className+'-moreButton').click(function(){var thisMoreButton=jQuery(this);var otherLists=jQuery('.'+settings.className+'-list').not(thisMoreButton.siblings('.'+settings.className+'-list'));hideList(otherLists);var thisList=thisMoreButton.siblings('.'+settings.className+'-list');if(thisList.filter(":visible").length>0){hideList(thisList);}else{showList(thisList);}}).bind('mouseenter',function(){jQuery(this).addClass('morebuttonhover');}).bind('mouseleave',function(){jQuery(this).removeClass('morebuttonhover');});_this.hide().replaceWith(replacement).appendTo(replacement);var thisListBox=replacement.find('.'+settings.className+'-list');var thisListBoxSize=thisListBox.find('.'+settings.className+'-item').length;if(thisListBoxSize>settings.listboxMaxSize)
thisListBoxSize=settings.listboxMaxSize;if(thisListBoxSize==0)
thisListBoxSize=1;thisListBoxSize=thisListBoxSize*1.4;var thisListBoxWidth=Math.round(_this.width()+5);if(jQuery.browser.safari)
thisListBoxWidth=thisListBoxWidth*0.94;replacement.css('width',thisListBoxWidth+'px');thisListBox.css({width:Math.round(thisListBoxWidth-5)+'px',height:thisListBoxSize+'em'});_this.change(function(){jQuery('.'+settings.className+'-currentItem',replacement).text($(this).find('option:selected').text());});});}
jQuery.fn.unselectbox=function(){var commonClass='jquery-custom-selectboxes-replaced';return this.each(function(){var selectToRemove=jQuery(this).filter('.'+commonClass);selectToRemove.replaceWith(selectToRemove.find('select').show());});}

function load_movies(url){var hash=proccess_hash_search(url,'movie/search/');if(hash&&url.indexOf('#')==-1){window.location.hash=hash;return;}
var url_new='http://'+window.location.host+'/movie/search/'+hash;$('#movies').animate({opacity:'0.1'},1000);url_new=prepareUrl(url_new);$.ajax({url:url_new,async:true,type:"post",dataType:"json",success:function(data){if(data.success==true){if(data.pager){$('div.paging').empty();;$('div.paging').html(data.pager);}else{$('div.paging').empty();}
if(data.total){$('div.info .total').html(data.total);}else{$('div.info .total').html('0');}
if(data.added){$('div.info .added').html(data.added);}else{$('div.info .added').html('0');}
if(data.pic){$('div.descbox').empty();$('div.descbox').append(data.pic);$('div.descbox').show();if(!data.has_trailer){$('div.trailer-box').hide();}else{$('div.trailer-box').show();}}else{$('div.descbox').hide();}
if(data.sort){$('p.sort').html(data.sort);}
$('#movies').empty().html(data.content);$('#movies img').preload({placeholder:presets.image_url+'waiting.jpg',notFound:presets.image_url+'noimage.jpg'});$('#movies').animate({opacity:'1'},2000);}else{showFlashData('error','<strong>Sorry.</strong> Something goes wrong...');}}});}
loadMovieCall=function(hash){if(hash==''){hash=proccess_hash_search(window.location.href);}
if(hash!=''){load_movies('http://'+window.location.host+'/movie/search/#'+hash);}else{load_movies(window.location.href);}
selectHashCombo(hash,'#movie_filters');};$(document).ready(function(){$.historyInit(loadMovieCall);$("#content .sidebar .dvd-search select").selectbox({animationSpeed:'fast'});$('#category_list a').click(function(){$('#category_list a').removeClass('active');$(this).addClass('active');load_movies($(this).attr('href'));return false;});$('div.paging a').live('click',function(){if(!$(this).hasClass('end')){load_movies($(this).attr('href'));}
return false;});$('#movie_filters input[type=submit]').click(function(){var search_url='';if($('#website').val()){search_url=search_url+'website/'+$('#website').val()+'/';}
if($('#director').val()!=''){search_url=search_url+'director/'+$('#director').val()+'/';}
if($('#series').val()){search_url=search_url+'series/'+$('#series').val()+'/';}
if($('#studio').val()){search_url=search_url+'studio/'+$('#studio').val()+'/';}
if($('#category').val()){search_url=search_url+'category/'+$('#category').val()+'/';}
window.location.hash=search_url;return false;});$('p.sort a').live('click',function(){load_movies($(this).attr('href'));return false;});});

