/****************************

Initialise Bungert v5 Site JavaScript

	Requires jQuery
	
	Stephen Bungert
	www.bungert.co.uk
	
****************************/


function fadeInPortfolio()
{
	$('div.portGridImage').css('opacity', '0');
	
	$('div.portGridImage').each(function(index){
		duration = index * 200;
		$(this).delay(duration).fadeTo('normal', 1);
	});
}

$(document).ready(function()
{
	// Hide titles by default incase of reload
	$('.portGridImage p').css('display', 'none');
	
	
	
	// Hide related item image incase of reload
	$('div.portRelatedItems .sidebarList .sblItem a.relatedItemTitleLink').siblings('.relatedItemImageLink').children('.relatedItemImage').removeClass('show');
	
	fadeInPortfolio();
	
	// Related items
	$('div.portRelatedItems .sidebarList .sblItem a').bind('mouseover', function() {
		$(this).siblings('.relatedItemImageLink').children('.relatedItemImage').toggleClass('show');
		//$(this).siblings('.relatedItemImageLink').children('.relatedItemImage').slide("slide", { direction: "left" }, 500);
		
	}).bind('mouseout', function() {
		$(this).siblings('.relatedItemImageLink').children('.relatedItemImage').toggleClass('show');
		//$(this).siblings('.relatedItemImageLink').children('.relatedItemImage').slide("slide", { direction: "left" }, 500);
	});
	
	
	
	// Move Titles inside link
	$('.portGridImage a').each(function(){
		$(this).siblings('p').appendTo($(this));
	});
	
	// Portfolio images
	$('.portGridImage a').bind('mouseenter', function() {
		$(this).fadeTo('fast', 1);
		$(this).children('p').css('display', 'inline-block'); // Show title
		
		// Adjust height of the titles
		var height = $(this).children('p.portImageTitle').height();
		$(this).children('p.portImageTitleBg').height(height);
		
	}).bind('mouseleave', function() {
		$(this).children('p').css('display', 'none'); // Hide title
		$(this).fadeTo('fast', 0.33);
	});
	
	// carousel
	if ($('ul.portfolioImageGrid').length >= 1 && $('.portfolioCarousel li').length > 4) {
		$('ul.portfolioImageGrid').jcarousel();
		
		if ($('.jcarousel-list').length >= 1) {
			$('.jcarousel-list').after('<div class="clearer"></div>');
		}
	}
	else
	{
		$('.portfolioCarousel').after('<div class="clearer"></div>');
	}
	
	
	
	// Lightbox
	if ($("a[rel^='prettyPhoto']").length >= 1) {
	$("a[rel^='prettyPhoto']").prettyPhoto({markup: '<div class="pp_pic_holder"> \
      <div class="pp_content_container"> \
       <div class="pp_left"> \
       <div class="pp_right"> \
        <div class="pp_content"> \
         <div class="pp_loaderIcon"> \</div> \
         <div class="pp_fade"> \
          <div class="pp_hoverContainer"> \
           <a class="pp_next" href="#">next</a> \
           <a class="pp_previous" href="#">previous</a> \
          </div> \
          <div id="pp_full_res"> \</div> \
          <div class="pp_details clearfix"> \
           <a href="#" class="pp_expand" title="Expand the image"> \Expand</a> \
           <a class="pp_close" href="#">Close</a> \
           <p class="pp_description"> \</p> \
             <div class="pp_nav"> \
              <a href="#" class="pp_arrow_previous">Previous</a> \
              <p class="currentTextHolder">0/0</p> \
              <a href="#" class="pp_arrow_next">Next</a><div class="clearer"></div> \
             </div><div class="clearer"></div> \
          </div> \
         </div> \
        </div> \
       </div> \
       </div> \
      </div> \
     </div> \
     <div class="pp_overlay"></div> \
     <div class="ppt"></div>'});
	}
	
	
	
	
	// List rollovers
	$('.pageNav li a').bind('mouseover', function() {
		$(this).parent().toggleClass('ro');
		
	}).bind('mouseout', function() {
		$(this).parent().toggleClass('ro');
	});
	
	
	
	$('#column3 .portfolioFilter ul li').each(function() {
		var href = 'http://www.bungert.co.uk/' + $(this).children('a').attr('href');
		
		if (href == window.location.href)
		{
			var text = $(this).children('a').text();
			$(this).children('a').remove();
			$(this).addClass('selected').text(text);
		}
	});
});
