
$(document).ready(function() {

	/* Loading page */
	
	$("#container").css("visibility", "hidden");

	setTimeout(function() {
		jQuery("#container").hide().css("visibility", "visible").fadeIn(500);
	}, 500);

	$(window).scroll(function( ) {
	    $("#scrollTop").stop().fadeTo( 250, $(this).scrollTop() === 0 ? 0 : 1 );
	});

	$("#scrollTop").click(function(e){
		$("html, body").animate({scrollTop: $("header").offset().top - 40}, 750);	
		e.preventDefault();
		
	});

	$("[rel='contact']").click(function(e){

		$("html, body").animate({scrollTop: $("#main").offset().top - 24}, 750, function() {
			
		});

		e.preventDefault();
		
	});

	/* Portfolio */

	$("#portfolio-items").cycle({
		fx:     'scrollLeft', 
		speed:  '600', 
		timeout: 0, 
		prev: '.portfolio-nav .prev',
		next: '.portfolio-nav .next',
		cleartypeNoBg: true
	});

	$('.portfolio-nav').hide();

	$('#portfolio').hover(
		function() { $('.portfolio-nav').fadeIn(300); },
		function() { $('.portfolio-nav').fadeOut(300); }
	);

	$("#portfolio-items")
		.find(".item")
			.hover(
				function() { $(".hover", this).fadeIn(300); },
				function() { $(".hover", this).fadeOut(300); }
	);
			
	/* Item slides */	
				
	$("div[id^=itemSlide]").each(function(index) {
	
		var itemNumber = index+1;
	
		$("#itemSlide" + itemNumber).cycle({
			fx: 'fade', 
			speed: '1000', 
			timeout: 0, 
			pager: '#item' + itemNumber + ' .explore-item-nav div',
			cleartypeNoBg: true,
			pagerAnchorBuilder: function() {
				return '<a href="#"></a>';
			}
		});

	});

	$('div[title!=""]').each(function() {

		var a = $(this);

		a.hover(function() {
			showAnchorTitle(a, a.data('title')); 
			}, 
			function() { 
				hideAnchorTitle();
			}
		)
		.data('title', a.attr('title'))
		.removeAttr('title');

	});

});

/* Show item function */

function showItem(itemID, hashID) {
	
	if ($(".explore-item:visible").length > 0) {
		
		$("html, body").animate({scrollTop: $("#portfolio").offset().top},'slow', function() {

			$(".explore-item:visible").slideUp(500, function() { 
				
				$("#item" + itemID).slideDown();
				$(".explore-item-slides").hide().css("visibility", "visible").delay(1000).fadeIn(500);
				$(".itemInfo").hide().css("visibility", "visible").delay(2000).fadeIn(500);
				
			});
					
		});
			
    } else {
    
		$("html, body").animate({scrollTop: $("#portfolio").offset().top},'slow', function() {

			$("#item" + itemID).slideDown();
			$(".explore-item-slides").hide().css("visibility", "visible").delay(1000).fadeIn(500);
			$(".itemInfo").hide().css("visibility", "visible").delay(2000).fadeIn(500);
			
		});
    
    }
	
	//window.location.hash = hashID;

}

/* Close item function */

function closeItem(itemID) {

	$("html, body").animate({scrollTop: $("#portfolio").offset().top},'slow', function() {
		$(".itemInfo:visible").fadeOut(500);
		$(".explore-item-slides:visible").fadeOut(500);
		$("#item" + itemID).slideUp(500);
	});
}

function showAnchorTitle(element, text) {
	$('#anchorTitle span').html(text).show();
}

function hideAnchorTitle() {
	$('#anchorTitle span').hide();
}



