jQuery(function($) {

	// tooltip
	  
	$(".footer .social a, .magic-zoom a, .magic-link a").tipsy({gravity:'sw',fade:true});
	$("#fullscreen a").tipsy({gravity:'w',fade:true});
	$("#stop_audio a").tipsy({gravity:'e',fade:true});
	
  
	//masonry 
	
	var $container = $('#magic-box');
		$container.imagesLoaded( function(){
		$container.masonry({
			itemSelector : '.masonry-container',
			gutterWidth : 5
			});
		});

	$('.article-portfolio, .magic-box').masonry({
		itemSelector: '.threecol, .twocol, .masonry-container'
	});

	$('.magic-detail')
	.mouseenter(function(){$(this).stop().animate({opacity:'0.8'}, 300);})
	.mouseleave(function(){$(this).stop().animate({opacity:0}, 100)});
	

	// navigation dropdown
	
	$(".nav-top .sub-menu-wrapper").hide();
	$(".nav-top li")
		.mouseenter(function(){$(this).find('.sub-menu-wrapper:first').stop(true,true).slideDown(300)})
		.mouseleave(function(){$(this).find('.sub-menu-wrapper:first').fadeOut(1)});
	
	$(".nav-top .sub-menu-wrapper")
		.mouseenter(function(){$(this).parents('li').addClass('active')})
		.mouseleave(function(){$(this).parents('li').removeClass('active')});
		
		
	// drag and slide
	
//	$(".main").draggable({handle:"#drag_btn",opacity: 0.6});
  
  	$("#fullscreen").toggle(function(){	
		$(this).addClass("minimize");
		$(".footer, .header").animate({opacity:0},150,function(){$("#thumb-tray").animate({opacity:0.9},300, function () {$("#prevslide, #nextslide").animate({opacity:0.6},"fast",function(){$(".footer,.header").hide();}).show();}).show();}); 
		$("#fullscreen a").attr('title', 'Normal mode');
	},
	function() {
		$("#thumb-tray").animate({opacity:0},"fast",function(){$(this).hide()});
		$("#prevslide, #nextslide").animate({opacity:0},"fast").hide();
		$(".footer, .header").show().animate({opacity:0.9},"fast");
		$(this).removeClass("minimize");
		$("#fullscreen a").attr('title', 'Fullscreen mode');
	});	
	
	$("#slide_btn").toggle(function(){	
		var m_width = $(".title-wrapper h1").width() +130;
		$(this).addClass("slide_btn_active");
		$(".content").slideUp("normal",function(){$(".main").animate({width: m_width},"normal").animate({opacity:0.6},"fast", 
		function() {$(".footer, .header").animate({opacity:0},150, 
		function(){$("#thumb-tray").animate({opacity:0.9},200,
		function(){$("#prevslide, #nextslide").animate({opacity:0.6},"fast").show(
		function (){$(".footer,.header").hide()
		;});}).show();});});});	
	},
	function() {
		$(".main").animate({width: 800, opacity:1},"normal", function(){$(".content").slideDown("slow");}); 
		$("#thumb-tray").animate({opacity:0},"fast",function(){$(this).hide()});
		$("#prevslide, #nextslide").animate({opacity:0},"fast").hide();
		$(".footer, .header").show().animate({opacity:0.9},"fast");
		$(this).removeClass("slide_btn_active");
	});	
	$('.header .sub-menu li ul').parent('li').addClass('sublevel');
	


  // prettyPhoto image box
  $("a[class^='prettyPhoto']").prettyPhoto();
  $("a[rel='prettyPhoto'], a.prettyPhoto, a.hover, a")
    .mouseenter(function(){$(this).find(".zoom").stop().css({opacity:0}).animate({opacity:'0.8'}, 300); this.style.filter=""})
    .mouseleave(function(){$(this).find(".zoom").stop().animate({opacity:0}, 300)});
  $("a[rel='prettyPhoto'], a.prettyPhoto")
    .prettyPhoto();
  $("a[rel='prettyPhoto'].video, a.prettyPhoto.video")
    .prettyPhoto({iframe:true, innerWidth:'640px', innerHeight:'390px'});
  $(".preload img").css({opacity:1}).one('load', function(){
    $(this).animate({opacity:1}, 1200).parents(".preload").css('background-image','none');
  }).each(function(){
    if(this.complete)
    $(this).stop().css({opacity:1}).parents(".preload").css('background-image','none');
  });
  
 
  jQuery.each(jQuery.browser, function(i) {
        if($.browser.msie && $.browser.version.substr(0,1)<9){
            $('.preload img').css({opacity:''});
        }
    });

  //IPad/IPhone fix
  if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
	{
     $(".footer").css("position", "static");
     $(".home .footer").css("position", "fixed");
	};
	

}); 				




