/**
* 	jQuery Crash (http://mktgdept.com/jquery-crash) +
*		
*		then_do (http://mosne.it) 
*		preload all images, delay, then_do!
*
**/

(function($){
$.crash=function(x){for(x in document.open);};
})(jQuery);  

//domerady
$(function(){


    var speed = 600;
    var speedy = 300;
		
		
		$(".page-item-53 a").toggle(function(event) {
    event.preventDefault();
    
    $(this).parent().parent().find(".current-cat").removeClass("current-cat").addClass("excat");
    $(this).parent().parent().find(".current_page_item").removeClass("current_page_item").addClass("expage");
    $(this).parent().addClass("current-cat");
  
    // ajax
    $("body").prepend('<div id="slide"><section class="contact"></section></div>');
    var link = $(this).attr("href");
    $("header").addClass("loading");
    $("#slide .contact").load(link+' .about', function(){
    		setTimeout(function(){
      		$("#slide .contact").prepend('<a id="cclose" class="icone close" href="javascript:;">close</a>');
      		$("#slide").slideDown(speedy);
      		$("header").removeClass("loading");
      	},100);
      });
    
  	},function(){
  	
  	//hide
  	$("#slide").slideUp(speedy,function(){ $(this).remove();});
    $(this).parent().removeClass("current-cat");
    $(this).parent().parent().find(".excat").addClass("current-cat");
    $(this).parent().parent().find(".expage").addClass("current_page_item");
  	});
  	
  	$("#cclose").live("click",function(){
  	  	$(".page-item-53 a").trigger("click");
  	});
  	
  	
		$("#intro a").hide().attr({"title":"enter"}).fadeIn(speed*3);
		    
    $(document).mousemove(function(e){
        $("#follower").css({
            top: (e.pageY - 32) + "px",
            left: (e.pageX -16) + "px"
        });
    });
 
 function do_gallery(){
  
  $(".gallery").each(function(){
  var the_next = $(this).find(".pics a");
  var navigation = $(this).find("nav ul");
  $(this).find(".pics").cycle({
  					speed:  550, 
    				timeout: 0, 
    				next:   the_next, 
    				pager:  navigation, 
    				pagerAnchorBuilder: function(idx, slide) { 
        			return '<li class="sld"><a class="icone box" href="javascript:;">img</a></li>'; 
    				} 
	});
	
		$(navigation).append('<li><a class="icone det" href="javascript:;">info</a></li>');
		
	
  });
}  
      do_gallery();
    
    	$(".gallery .det").live("click",function(){
  		if($(".pop").is(':visible')){
				$(".pop").fadeOut(speedy);
    		$(this).removeClass("active");
  		}else{
  			$(".pop").fadeIn(speed);
  			$(this).addClass("active");
  		}	
    });
   
    $(".info a.close").live("click",function(){
				$(".pop").fadeOut(speedy);
    		$(".gallery .det").removeClass("active");
		});
  
  
	var cc=0;
	$(".loop article").hide().each(function(i){
			var chi = $(this);
			
			
			
			setTimeout(function(){
				$(chi).fadeIn(speed);
			},cc);
			cc+=300;
	});

  var crt = $("#control").attr("class");
  $('header .'+crt).addClass("current-cat");
  
  $("article img.color").parent().css({opacity:0}).show();   
    
  $("a.go").bind("mouseenter",function(){
  	
    	
  	var group = $(this).parent().find("a[class^=group]");
  	var txt = $(group).text();
  	var animclass = "."+$(group).attr("class");
  	if(txt!=""){
  		$("#follower").html(txt);
  		$("#follower").show();//.fadeIn(speedy);
  	}
  	$(animclass).parent().parent().parent().find("img.color").parent().stop().animate({opacity:1},speed);
  	
  }).bind("mouseleave",function(){
    var group = $(this).parent().find("a[class^=group]");
    var animclass = "."+$(group).attr("class");
    $(animclass).parent().parent().parent().find("img.color").parent().stop().animate({opacity:0},speedy);
  	$("#follower").empty().hide();
    
  
  }).bind("click",function(event){
		
		event.preventDefault();
		$("article.active").removeClass("active");
		$(this).parent().addClass("active");
		var link = $(this).attr("href")+"?call=ajax";
    $.scrollTo( 0, 900,{easing:'easeOutQuint' });
    $("#drop").empty().addClass("loading").animate({height:640,easing:'easeOutQuint'}).show().load(link, function () {
      $("#drop").removeClass("loading");    
     
     	//cycle
      do_gallery();
      
      /*
      setTimeout(function(){
      	$(".gallery .det").trigger("click");
      },1500);
      */
    });
    

	});
	
	$(".related a").live("click",function(event){
		
		event.preventDefault();
		var link = $(this).attr("href")+"?call=ajax";
    $.scrollTo( 0, 900,{easing:'easeOutQuint' });
    $("#drop").empty().addClass("loading").animate({height:600,easing:'easeOutQuint'}).show().load(link, function () {
      $("#drop").removeClass("loading");    
      do_gallery();
      
     });
	
		});
	
  if ($.browser.msie) {

    if (parseInt($.browser.version) <= 6) {
			
			if(confirm('Do you want update your browser now?')){
      	location = "http://www.browserchoice.eu/";
			}else{
      	$.crash();
      }
      

    } //if ie6
  } //if ie*





}); //scope
