// MOSNE FUNCTIONS

$(document).ready(function(){
    
      var COOKIE_NAME = 'bewzoom';
      var options = { path: '/', expires: 300 };
      var castoptions = { path: '/'};
      var zoomcookie = $.cookie(COOKIE_NAME);
     
      if(zoomcookie == null){
        $.cookie(COOKIE_NAME, 100, options);
        var zoomcookie = 100;
      }
     var scaledy=parseInt(224+2*(zoomcookie));
     var scaledx=parseInt(168+1.5*(zoomcookie));
     var padscaledx=22+parseInt(168+1.5*(zoomcookie));
     
     $("#show img").css({height:scaledy+"px",width:scaledx+"px"}); 
     
     if ($.browser.msie) {
     
         $(".page-template-news-php .grey").css({marginTop:"-28px"});
     
         if (parseInt($.browser.version)<=7){
            
            var toff = $("#top").offset();
            var okw = $(window).width();
            
            
           
            var veryok= okw-toff.left;
            $("#top").width(veryok);    
            
           
            //$("#vertical").css({position:"relative"});
            $("#show img").each(function(){
                $(this).parent().parent().css({width:scaledx+"px"});
            });
         } //if ie6-7
         if (parseInt($.browser.version)==7){
         
          var okh = $(document).height();
          $("#vertical").height(okh);    
         
         }//if ie7
      } //if ie*
      
      
     var names = $("ul#show li a").not(".plus");
     Cufon.replace('a.cat',{hover:true});
     Cufon.replace('a.nicetitle',{hover:true});
     Cufon.replace('#tophd h2');
     Cufon.replace(names,{hover:true});
    
     var posxy=$("#tophd").offset();
     var tx=$("#tophd").width();
     var ty=1900+$("#tophd").height();
    
     $("#blind").css({top:0, left: posxy.left, width:tx, height:ty}).show();
    
     setTimeout(function(){
     
     $("#blind").hide("slide", { direction: "right"  }, 900);
     
     },2000);
     
     
     
     
     $("#tabs").tabs();
     
     $('#myslider').slider({
            value: zoomcookie,
            slide: function(event, ui) { 
                var scaledy=parseInt(224+2*(ui.value));
                var scaledx=parseInt(168+1.5*(ui.value));
                $("#show img").css({height:scaledy+"px",width:scaledx+"px"});
                 
                 if ($.browser.msie) {
                    if (parseInt($.browser.version)<=7){
                        $("#show img").each(function(){
                            $(this).parent().parent().css({width:scaledx+"px"});
                        });
                     } //if ie6
                 } //if ie*   
      
      
            },
            stop:function (event,ui){
               
               $.cookie(COOKIE_NAME, ui.value, options);
                
            }
      });
      
       $("#alltoall a.cat").click(function(){
               
        $("#alltoall .cat.active").removeClass("active").parent().find(".secondo").addClass("hidden").slideUp(600);
        $(this).parent().find(".secondo").removeClass("hidden").hide().slideDown(600);
        $(this).addClass("active");
        Cufon.refresh('a.cat'); 

        
     });

     $("#alltoall").find(".active:eq(0)").parent().parent().parent().find(".cat").trigger("mouseenter");
     
     $("#q").bind("click",function(){ $(this).select();});
     $("#q").bind("focus",function(){ $(this).val("");});
     $("#q").bind("blur",function(){ $(this).val("search"); });
     
      // $("#q").ajaxStart(function(){ $(this).addClass("ajax");});
    // $("#q").ajaxStop(function(){ $(this).removeClass("ajax");});
     
     $("#q").liveSearch({url: '/index.php?ajax=1&s=', loadingClass: 'ajax'});
     
     $(".add").live("click",function(){
        
        
        var bname = $(this).attr("alt");
        // var blnk = $(this).attr("rel");
        var bid = $(this).attr("rel");
        var thepics = $(this).parent().parent().find("img:eq(0)");
        var bpics = $(thepics).attr("src");
        $(thepics).effect("transfer",{ to: "#chartlist li:last", className: 'ui-effects-transfer' },1000);
       
       //alert(bid+"//"+bname+";"+bpics); 
       
        $.cookie('bwchart['+bid+']', bname+";"+bpics , castoptions); 
        
        $(this).text("casting");
        $(this).attr({"title":"remove from my casting"});
        $(this).removeClass("add").addClass("rem");
        //alert("add"+bname);
        $("#mycast").trigger("updatecasting");
        
        
     });
     
     $(".rem").live("click",function(){
     
        var bname = $(this).attr("alt");
        var bid = $(this).attr("rel");
        
        var thepics = $(this).parent().parent().find("img:eq(0)");
        $("#chartlist li:last").effect("transfer",{ to: thepics, className: 'ui-effects-transfer' },1000);
        
        $.cookie('bwchart['+bid+']', 'no' , castoptions); 
       
        $(this).text("+");
        $(this).attr({"title":"add to my casting"});
        $(this).removeClass("rem").addClass("add");
        
        $("#mycast").trigger("updatecasting");

        //alert("remove"+bname);
     
     });
     
       $("#clearcasting").live("click",function(){
     
        $("#mycast").trigger("deletecasting");

        //alert("remove"+bname);
     
     });
     
     $("li.page-item-208").append('<div id="mycast">');
     
     $("#mycast").bind("updatecasting", function(){
     
      $("#feedb").addClass("wloading"); 
      $(this).load("/wp-content/themes/bew/mycasting.php?code="+Math.random(1000),function(){
        $("#feedb").removeClass("wloading");
      });
      
    });
    
    
    $("#mycast").bind("deletecasting", function(){
     
      $("#feedb").addClass("wloading"); 
      $(this).load("/wp-content/themes/bew/mycasting.php?delete=now&code="+Math.random(1000),function(){
        $("#feedb").removeClass("wloading");
      
      setTimeout(function(){
      
       document.location=document.location.href
      
      },300);
      
      });
      
      
    });
    
    
    
    $("#mycast").trigger("updatecasting");
     
     $("#show img").each(function(i){
		
		var curr = $(this).parents("li");
		var currimg = $(this);
		$(currimg).parent().parent().addClass("imgloading");
		var the_src= $(currimg).attr("src");
		var img = new Image();					
	    
	    $(img).load(function () {
	        $(currimg).css({"opacity":0});
	        $(currimg).attr("src", the_src);
	        $(currimg).parent().parent().removeClass("imgloading");
	        
	    	$(currimg).animate({"opacity":1},3000,"easeOutQuart",function(){
	    });
	    
	    }).attr("src",the_src);	
	
	});	
	   
	
	
	
	$("#mycast a").live("mouseover",function(){
	   
	   $(this).parent().find(".wtips").show();
	       
	});
	$("#mycast a").live("mouseout",function(){
	   
	   $(this).parent().find(".wtips").hide();
	       
	});
	
	setTimeout(function(){
	   $(".cat.active").trigger("click");
	},900);
	
	$.scrollTo.defaults.axis = 'y';
    var $paneTarget = $('#scrolly');
    var globalspeed=900;
    
    $paneTarget.scrollTo($("#scrolly li.current"),globalspeed,{offset:{top:-126},easing:"easeOutQuart"});

	
	$('#vertical').bind('mousewheel',function(event, delta) {
			
			event.stopPropagation();
			event.preventDefault();							 
			
		if (delta > 0){
		  	

	
			var deltapix = "-=254px";
			$paneTarget.stop().scrollTo(deltapix,globalspeed,{easing:"easeOutQuart"});
		        
		}else if (delta < 0){
			
			var deltapix = "+=254px";
			$paneTarget.stop().scrollTo(deltapix,globalspeed,{easing:"easeOutQuart"});
			
			}
	});
    
	$("#goup").bind("mouseenter",function(){
	
	       var deltapix = "-=254px";
			$paneTarget.stop().scrollTo(deltapix,globalspeed,{easing:"easeOutQuart"});
	
	});
	
	$("#godown").bind("mouseenter",function(){
	
	       var deltapix = "+=254px";
			$paneTarget.stop().scrollTo(deltapix,globalspeed,{easing:"easeOutQuart"});
	
	});
	
	$("#goup").bind("click",function(){
	
	       var deltapix = "-=240px";
			$paneTarget.stop().scrollTo(deltapix,globalspeed,{easing:"easeOutQuart"});
	
	});
	
	$("#godown").bind("click",function(){
	
	       var deltapix = "+=240px";
			$paneTarget.stop().scrollTo(deltapix,globalspeed,{easing:"easeOutQuart"});
	
	});
	
	
	$("#fastthumb li").not(".current").find('img').stop().animate({opacity:.2});
	
	$("#fastthumb, #goup, #godown").hover(function(){
	
	$("#fastthumb li").find('img').stop().animate({opacity:1});
	
	},function(){
	
	$("#fastthumb li").not(".current").find('img').stop().animate({opacity:.2});
	
	});
	
	$(".bprint").click(function(){
	    
	    /*$("#ci, #tophd h2, #gallery img, #biography,#mypage, #foot").jqprint({ operaSupport: true, importCSS: true });
        $("#inprinting").slideDown("slow");
       
        setTimeout(function(){
        $("#inprinting").slideUp("slow");
        },(7*1000));
        */
        window.print();
	   
	});
	/*
	$("#inprinting").click(function(){
	   $(this).slideUp("slow");
	})
	*/
	
	$(".bcontact").click(function(){
      
      
      var t = encodeURI(document.title); 
      var url = encodeURI(document.location.href);
	  document.location.href = "mailto:info@blackewhite.com?subject="+t+"&body="+url; 
	   
	});
	
	$("a.goback").click(function(){
	   
	   history.back();
	   
	});
	
    
    
}); //scope 
