$(document).ready(function() {

	// Initialisoi pretty photo
	$("a[rel^='prettyPhoto']").prettyPhoto();
	hoverBoxSlider();
	$(".btn-slide").click(function(){
	$("#panel").slideToggle("slow");
	$(this).toggleClass("active");
	});
	
	// geneerinen hover stylen mouseover
	$("body").delegate(".btnHover", "mouseover", function(){
		try{
			lastBgPosition = determine_bg_pos($(this));
			var newPos = lastBgPosition.substr(0, lastBgPosition.indexOf(' '))+' bottom';
  			$(this).css({'background-position' : newPos, 'cursor' : 'pointer'});
		}catch(e){
			alert(e.message);
		}
	});
	$("body").delegate(".btnHover", "mouseout", function(){
		$(this).css('background-position',lastBgPosition);
	});		
	// Menu color change
	$(document).scroll(function(){
    var el = $('.selectedwork'),
        top = $('#projectsgrid').offset().top - $(document).scrollTop();
    if (top < 200 && !el.is('.bg-black')){
        $(el).addClass('bg-black');
    }
    if (top > 200 && el.is('.bg-black')){
        $(el).removeClass('bg-black');
    }  
});
});

function determine_bg_pos(obj){
	// parameter obj is something like $('#my-div')
   	var pos = $(obj).css("background-position");
   	if (pos == 'undefined' || pos == null) {
      		pos = $(obj).css("background-position-x") +' ' +  $(obj).css("background-position-y"); //die in hell
   	}
   	return pos;
}



// Description teksti kuvan päälle
function hoverBoxSlider() {
	$('.thumbover').hover(function(){
		$('.hoverBox', this).fadeIn().animate({top:'0px'},{queue:false,duration:500});
	}, function(){
		$('.hoverBox', this).animate({top:'-90px'},{queue:false,duration:500});
	});
}


// Boxien hover
$("body").delegate(".hover", "mouseover", function(){
	$(this).parent().children("div").eq(1).animate({ 
		top: "57px"					
	}, 200, function() {
		// Animation complete.		
		return true;
	});
});


/*
	$(window).resize(function(){
		var wWidth = $(window).width();
		$('#esittely').css('width',wWidth);
	}); 
	var wWidth = $(window).width();
	$('#esittely').css('width',wWidth);
	$('#esittely').everyTime(10,function(){
		$('#esittely').animate({left:"0px"}, 4000).animate({left:"-900px"}, 1000).animate({left:"-900px"}, 4000).animate({left:"-1550px"}, 1000).animate({left:"-1550px"}, 3000).animate({left:"0px"}, 900);
	});
*/

/*
function socialLinks() {
	$('#socialMedia').hide();
	$('#socialMedia').fadeIn().animate({ top:'300px' },{queue:false,duration:900});

	$('#socialMedia').stickyfloat({ duration: 400, offsetY: 300 }); 
	$('h3.facebookText').hide();
	$('h3.vimeoText').hide();
	$('h3.flickrText').hide();
	
	$('#facebook').hover(function(){
		$('h3.facebookText').fadeIn().animate({top:'315px', left: '910px'},{queue:false,duration:500});
	}, function(){
		$('h3.facebookText').animate({left:'1020px'},{queue:false,duration:500}).fadeOut();
	});
	
	$('#vimeo').hover(function(){
		$('h3.vimeoText').fadeIn().animate({top:'365px', left: '910px'},{queue:false,duration:500});
	}, function(){
		$('h3.vimeoText').animate({left:'1020px'},{queue:false,duration:500}).fadeOut();
	});
	
	$('#flickr').hover(function(){
		$('h3.flickrText').fadeIn().animate({top:'415px', left: '910px'},{queue:false,duration:500});
	}, function(){
		$('h3.flickrText').animate({left:'1020px'},{queue:false,duration:500}).fadeOut();
	});
}
*/

