$(document).ready(function(){wzbjsobj.loadThumbs(0,'');wzbjsobj.countWebsites();wzbjsobj.initEventHandlers()});var searchstring='';var current=parseInt($('#page').val());var controlnav=0;var stopnext=false;var wzbjsobj={initEventHandlers:function(){$('#about_link,#howto_link,#submitsite_link').bind('click',function(e){var elemid=e.target.id;$('#overlay').show();$('#previewContainer').show();if(elemid=='about_link')$('#about').show();else if(elemid=='howto_link')$('#howto').show();else if(elemid=='submitsite_link')$('#submitsite').show();e.preventDefault()});$('._closesection',$('#previewContainer')).bind('click',function(e){var $this=$(this);$this.parent().hide();wzbjsobj.closeBox();e.preventDefault()});$('#submit_form input').bind('focus',function(){$('#submit_success').empty()});$('#newsite').bind('click',function(){var new_site_email=$('#new_site_email').val();var new_site_url=$('#new_site_url').val();if(new_site_email==''||new_site_url==''){$('#submit_success').html('Please fill both values');return}$('#ajaxload').show();var url='php/enginecontroller.php';$.ajax({type:'POST',url:url,timeout:30000,dataType:'json',data:'SubmitNewSite=1&new_site_email='+new_site_email+'&new_site_url='+new_site_url,success:function(data,textStatus){if(data.result==1){$('#ajaxload').hide();$('#new_site_email').val('');$('#new_site_url').val('');$('#submit_success').html('Thank you for your submission!')}},error:function(){$('#ajaxload').hide();$('#new_site_email').val('');$('#new_site_url').val('');$('#submit_success').html('Thank you for your submission!')}})});$('#searchsite').bind('click',function(e){$this=$(this);$inputsearch=$this.prev();searchstring=jQuery.trim($inputsearch.val());if(searchstring=='')return;wzbjsobj.reset();$('#filter').animate({'left':'-90px'},1000);$('#sett_must,#sett_may,#sett_without,#sett_pattern').hide();$('#search_term').html(searchstring).parent().show();current=0;wzbjsobj.loadThumbs(current,'');$inputsearch.val('');e.preventDefault()});$('#reset_search').bind('click',function(){searchstring='';$('#search_term').html('').parent().hide();$('#filter').animate({'left':'-5px'},1000);$('#sett_may').show();wzbjsobj.loadThumbs(0,'')});$("#menu input").keypress(function(e){if((e.which&&e.which==13)||(e.keyCode&&e.keyCode==13)){$("#searchsite").click();return false}else{return true}});$('#next').bind('click',function(){if(stopnext){return}wzbjsobj.loadThumbs(current+1,'next');++current});$('#prev').bind('click',function(){if(current<=0){current=0;return}wzbjsobj.loadThumbs(current-1,'prev');--current});$('#thumbs a').live('click',function(e){var $this=$(this);$('#preview_img').empty();var ajaxpreviewtimeout=setTimeout("$('#preview_img').addClass('previewloading');",200);$('#overlay').show();$('#preview').show();var src=$this.next().val();var likes=$this.next().next().val();var url=$this.next().next().next().val();var websiteid=$this.attr('id');$('#likecount').html(likes);$('#visit').attr('href',url);$('#rating input').val(websiteid);$('<img />').load(function(){clearTimeout(ajaxpreviewtimeout);$('#preview_img').empty().append($(this))}).error(function(){clearTimeout(ajaxpreviewtimeout);$('#likecount').html(likes);$('#visit').attr('href',url);$('#rating input').val(websiteid)}).attr('src',src).attr('width','500').attr('alt','Screen');e.preventDefault()});$('#preview_next').bind('click',function(){var websiteid=$('#rating input').val(websiteid);var $thissite=$('#thumbs a[id='+websiteid+']');var $nextsite=$thissite.nextAll('a:first');if($nextsite.length>0){$nextsite.click()}else{$('#next').click();controlnav=1}});$('#preview_prev').bind('click',function(){var websiteid=$('#rating input').val(websiteid);var $thissite=$('#thumbs a[id='+websiteid+']');var $prevsite=$thissite.prevAll('a:first');if($prevsite.length>0){$prevsite.click()}else{$('#prev').click();controlnav=1}});$('#close').bind('click',function(){wzbjsobj.closePreviewMode()});$('._color',$('#colors')).bind('click',function(e){var $this=$(this);if($this.hasClass('included')||$this.hasClass('excluded')){$this.removeClass('included excluded');current=0;wzbjsobj.showFilter($this.attr('name'),0);wzbjsobj.loadThumbs(current,'')}e.preventDefault()});$('.colorwrap',$('#colors')).hover(function(e){var $this=$(this);$this.find('.options').show()},function(e){var $this=$(this);$this.find('.options').hide()});$('.include',$('#colors')).bind('click',function(e){var $this=$(this);var $color=$this.parent().prev();if($color.hasClass('included'))return;wzbjsobj.showFilter($color.attr('name'),1);$color.removeClass('excluded');$color.addClass('included');current=0;wzbjsobj.loadThumbs(current,'');e.preventDefault()});$('.exclude',$('#colors')).bind('click',function(e){var $this=$(this);var $color=$this.parent().prev();if($color.hasClass('excluded'))return;wzbjsobj.showFilter($color.attr('name'),-1);$color.removeClass('included');$color.addClass('excluded');current=0;wzbjsobj.loadThumbs(current,'');e.preventDefault()});$('#layout a').bind('click',function(e){var $this=$(this);$('#layout a').not($this).removeClass('selected');if($this.hasClass('selected'))$this.removeClass('selected');else $this.addClass('selected');current=0;wzbjsobj.showFilter('',2);wzbjsobj.loadThumbs(current,'');e.preventDefault()});$('#like').click(function(e){var website=$('#rating input').val();var url='php/enginecontroller.php?ts='+new Date().getTime();var data='Rate=1&website='+website;$.ajax({type:'POST',url:url,timeout:30000,dataType:'json',data:data,success:function(data,textStatus){$('#likecount').html(data.newrate);$('#'+website).next().next().val(data.newrate)},error:function(){}});e.preventDefault()})},loadThumbs:function(n,nav){$('#thumbs').hide();var ajaxtimeout=setTimeout("$('#loader').show();",50);var colors=wzbjsobj.getIncludedColors();var nocolors=wzbjsobj.getExcludedColors();var pattern=wzbjsobj.getSelectedPattern();var data='';data='LoadThumbs=1&current='+n+colors;data+=nocolors;data+=pattern;data+='&searchstring='+searchstring;var url='php/enginecontroller.php';$.ajax({type:'GET',url:url,timeout:30000,dataType:'json',data:data,success:function(data,textStatus){if(data.result=='1'){var _all=0;var imagesLength=data.nmbThumbs;if(imagesLength==0){clearTimeout(ajaxtimeout);$('#loader').hide();if(n==0)$('#thumbs').html('<span class="no_results">no results</span>').fadeIn(400);else $('#thumbs').show();--current;controlnav=0}if(imagesLength<30){stopnext=true;controlnav=0}else stopnext=false;for(var i=0;i<imagesLength;i++){$('<img />').load(function(){_all+=1;if(_all==imagesLength){clearTimeout(ajaxtimeout);$('#loader').hide();$('#thumbs').empty().html(data.html).fadeIn(400);if(controlnav==1&&$('#preview').css('display')!='none'){if(nav=='next')$('#thumbs a:first').click();else $('#thumbs a:last').click();controlnav=0}}}).error(function(){_all+=1;if(_all==imagesLength){clearTimeout(ajaxtimeout);$('#loader').hide();$('#thumbs').html(data.html).fadeIn(400);if(controlnav==1&&$('#preview').css('display')!='none'){if(nav=='next')$('#thumbs a:first').click();else $('#thumbs a:last').click();controlnav=0}}}).attr('src','http://www.tympanus.net/webzibition/screenshots/thumbs/'+data.images[i])}}},error:function(){}})},getIncludedColors:function(){var colors='';$('#colors a.included').each(function(){var $this=$(this);colors+='&'+$this.attr('name')+'=1'});return colors},getExcludedColors:function(){var colors='';$('#colors a.excluded').each(function(){var $this=$(this);colors+='&'+$this.attr('name')+'=-1'});return colors},getSelectedPattern:function(){var pattern='';var $patternsel=$('#layout a.selected');if($patternsel.length)pattern+='&pattern='+$patternsel.attr('name');return pattern},countWebsites:function(){var url='php/enginecontroller.php';$.ajax({type:'GET',url:url,timeout:30000,dataType:'json',data:'CountWebsites=1',success:function(data,textStatus){$('#counter').html(data.count)},error:function(){}})},showFilter:function(name,op){if(op==1){if($('#sett_colors_without').find('span.'+name).length){$('.'+name,$('#sett_colors_without')).remove();if($('#sett_colors_without').children().size()==0)$('#sett_without').hide()}if($('#sett_colors_may').find('span.'+name).length){$('.'+name,$('#sett_colors_may')).remove();if($('#sett_colors_may').children().size()==0)$('#sett_may').hide()}$('#sett_colors_must').append('<span class="'+name+'">&nbsp;</span>');$('#sett_must').show()}else if(op==-1){if($('#sett_colors_must').find('span.'+name).length){$('.'+name,$('#sett_colors_must')).remove();if($('#sett_colors_must').children().size()==0)$('#sett_must').hide()}if($('#sett_colors_may').find('span.'+name).length){$('.'+name,$('#sett_colors_may')).remove();if($('#sett_colors_may').children().size()==0)$('#sett_may').hide()}$('#sett_colors_without').append('<span class="'+name+'">&nbsp;</span>');$('#sett_without').show()}else if(op==0){if($('#sett_colors_must').find('span.'+name).length){$('.'+name,$('#sett_colors_must')).remove();if($('#sett_colors_must').children().size()==0)$('#sett_must').hide()}if($('#sett_colors_without').find('span.'+name).length){$('.'+name,$('#sett_colors_without')).remove();if($('#sett_colors_without').children().size()==0)$('#sett_without').hide()}$('#sett_colors_may').append('<span class="'+name+'">&nbsp;</span>');$('#sett_may').show()}else if(op==2){var selectedPattern=$('#layout a.selected');if(selectedPattern.length)name=selectedPattern.attr('name');$('#sett_layout span').remove();if(name==''){$('#sett_layout').hide()}else{$('#sett_layout').append('<span class="'+$('#layout a.selected').attr('name')+'">&nbsp;</span>');$('#sett_layout').show()}}},reset:function(){$('._color',$('#colors')).removeClass('included excluded');$('#layout a').removeClass('selected');$('#sett_colors_must').empty();$('#sett_must').hide();$('#sett_colors_without').empty();$('#sett_without').hide();$('#sett_layout').hide();$('#sett_colors_may').html('<span class="red">&nbsp;</span><span class="pink">&nbsp;</span><span class="purple">&nbsp;</span><span class="brown">&nbsp;</span><span class="yellow">&nbsp;</span><span class="blue">&nbsp;</span><span class="green">&nbsp;</span><span class="orange">&nbsp;</span><span class="white">&nbsp;</span><span class="gray">&nbsp;</span><span class="black">&nbsp;</span>')},closePreviewMode:function(){$('#preview').hide();$('#overlay').hide()},closeBox:function(){$('#previewContainer').hide();$('#overlay').hide()}};
