// JavaScript Document

$(window).load(function(){
	$(".preload div").addClass("scale-div").fadeOut("");
	$(".preload").fadeOut("slow",function(){
		$(this).remove();
		$.fancybox({
            'width': 600,
            'height': 610,
            'transitionIn': 'fade',
            'transitionOut': 'fade',
            'type': 'iframe',
            'href': 'http://i-am-david.com/my-grad-show-2011/'
        });
	});
	$(".wrapper").css("visibility","visible");
});

$(function(){
	$(".port-items").hover(
	function(){
		$(this).find("img").stop().animate({height:120},"slow",'easeOutBounce'); 
		$(this).find(".ico").stop(true,true).animate({top:60},"fast",'easeOutQuad').fadeIn();
		$(this).find("dt").stop().animate({height:120, backgroundPosition:"(0 -80px)"}, {duration:500}); 
	},
	function(){
		$(this).find("img").stop().animate({height:160},"",'easeInQuad'); 
		$(this).find(".ico").stop(true,true).animate({top:80},"",'easeInQuad').fadeOut();
		$
		(this).find("dt").stop().animate({height:160, backgroundPosition:"(0 0)"}, {duration:500}); 
	});
	
	$(".preload div").position({
	  my: "center center",
	  at: "center center",
	  of: ".wrapper"
	});
	
	var preloadH = $(".wrapper").height();
	//var bgImgPos = $(document).height()/2;
	$(".preload").css("height",preloadH);
	$(".preload div").hide().fadeIn(500);
	//$(".preload").animate({backgroundPosition:'(center' + bgImgPos +')'},"slow")
	
});

function portSlider(){
	var slider = $('#slider-visual').bxSlider({
		controls: true,
		mode: 'vertical',
		easing: 'swing'
	});
	
	$('#go-prev').click(function() {
		slider.goToPreviousSlide();
		//$("#slider-visual li").fadeOut("fast").fadeIn("slow");
		return false;
	});
	
	$('#go-next').click(function() {
		slider.goToNextSlide();
		//$("#slider-visual li").fadeOut("fast").fadeIn("slow");
		return false;
	});
}
		  
function thumbPreload(){
	  //portfolio-box
	  $('.item-list .port-items').hide();
	  var i = 0;
	  $('.item-list .port-items').each(function()
	  {
	  var me = this;
	  $(this).hide()
	  var j = $('.item-list .port-items').length*10;
	  setTimeout(function()
	  {
	  $(me).fadeIn();
	  }, i)
	  i += j
	  });
}

$(document).ready(function(){
	
		  thumbPreload();
		  jQuery.globalEval("portSlider()");
		  
			
		 $("#tweet-list").tweet({
			avatar_size: 32,
			count: 12,
			join_text: "auto",
			username: "toDavidMak",
			list: "design",
			loading_text: "loading list..."
		  });
			
		  $(".social a").each(function(index){
			  $(this).hover(
			  function(){
				  $(this).find("img").stop().animate({opacity: 0}, "");;
				  },
			  function(){
				  $(this).find("img").stop().animate({opacity: 1}, "");;
				  }
			  );
			  
		  });
		  
		  $("a[rel=stuffGroup]").fancybox({
				'autoScale'			: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'padding'           : 0,
				'autoScale'         : true
		  });
		  
		  
		  var deviceAgent = navigator.userAgent.toLowerCase();
		  var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
		  if (agentID) {
			  $("#mcs_container").removeAttr("id").css({height:268,overflow:"auto"});
		  }else{
			  $(".song").click(function() {
				$.fancybox({
						'padding'		: 0,
						'autoScale'		: false,
						'transitionIn'	: 'none',
						'transitionOut'	: 'none',
						'title'			: this.title,
						'width'		    : 680,
						'height'		: 495,
						'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
						'type'			: 'swf',
						'swf'			: {
							 'wmode'		: 'transparent',
							'allowfullscreen'	: 'true'
						}
					});
			
				return false;
				});
			  
			  
	      }
		  
});
	
		  
$(window).resize(function(){
	var winW = $(window).width(); 
		if((winW) < '1024'){
			$(".bx-next, .bx-prev").hide();	
			}
		else{
			$(".bx-next, .bx-prev").show();	
			}
});

