/*!
 * Sitepeople JavaScript Library v1.0.0
 * for my brother Martin
 * http://eatstars.com/
 *
 * Copyright 2010, Tom Neijman
 * Email tom.neijman AT sitepeople.nl
 * Date: Ma Jun 26 07:00:00 2010
 */

var contentHeight = 7.4;
var imageHeightHeadline = 50;
var imageHeightArticle = 100;

var stopBubbling = 0; // vreemd gedrag, herhaald event uitvoeren voorkomen, TN 20100708



$(document).ready(function(){
	initZoom();
	
    jQuery("#customer-carousel").jcarousel({
		wrap: 'circular',
        scroll: 9,
        initCallback: customer_carousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
	
	//portfolio
	$('#portfolio').cycle({ 
		fx:     'fade', 
		speed:  'fast', 
		timeout: 0, 
		next:   '#portfolio-next', 
		prev:   '#portfolio-prev' 
	});
	
	$(".active-nav").css("display", "block");

	$("#projects li").css("cursor","pointer");

	$("#projects li").hover(
		function () {
			$(this).css("border", "2px solid #3181CC");
			$(this).find("A").css("text-decoration", "underline");
			$(this).find("A").css("color", "#3181CC");
		},
		function () {
			$(this).css("border", "2px solid #b3d0ec");
			$(this).find("A").css("text-decoration", "none");
			$(this).find("A").css("color", "#0a0a0a");
		}
	);
	
	$("#projects li").click(
		function () {
			window.location.href =  $(this).find("A").attr("href");
		}
	);

	$("#back-button").hover(
		function () {
			$("#back-button").attr("src", "/gfx/but-back-a.png");
		},
		function () {
			$("#back-button").attr("src", "/gfx/but-back-i.png" );
		}
	);

	$(".forward-button").hover(
		function () {
			$(this).attr("src", "/gfx/but-forward-a.png");
		},
		function () {
			$(this).attr("src", "/gfx/but-forward-i.png" );
		}
	);

	$("#customer-carousel-next").hover(
		function () {
			$("#customer-carousel-next-but").attr("src", "/gfx/but-next-a.png");
		},
		function () {
			$("#customer-carousel-next-but").attr("src", "/gfx/but-next-i.png" );
		}
	);


	$("#customer-carousel-prev").hover(
		function () {
			$("#customer-carousel-prev-but").attr("src", "/gfx/but-prev-a.png");
		},
		function () {
			$("#customer-carousel-prev-but").attr("src", "/gfx/but-prev-i.png" );
		}
	);

	$("#portfolio-prev").hover(
		function () {
			$("#portfolio-prev-but").attr("src", "/gfx/but-prev-a.png");
		},
		function () {
			$("#portfolio-prev-but").attr("src", "/gfx/but-prev-i.png" );
		}
	);


	$("#portfolio-next").hover(
		function () {
			$("#portfolio-next-but").attr("src", "/gfx/but-next-a.png");
		},
		function () {
			$("#portfolio-next-but").attr("src", "/gfx/but-next-i.png" );
		}
	);

	$('.slider').each(function () {
		var current = "#" + $(this).attr("id");
		
		$(this).css("height", "29px");
		$(this).css("cursor", "pointer");
		$(this).css("background", 'url("../gfx/collapsable-show-i.png") no-repeat scroll 0 0 transparent');

		$(current).hover(
			function () {
				$(this).css("background", 'url("../gfx/collapsable-show-a.png") no-repeat scroll 0 0 transparent');
			},
			function () {
				$(this).css("background", 'url("../gfx/collapsable-show-i.png") no-repeat scroll 0 0 transparent');
			}
		);
	});	
	
	$('.collapsable').each(function () {
		var currentHeight;
		var current = $(this);
		var height = (current.height());
		
		currentHeight = Math.max(height, (imageHeightArticle));
		currentHeight = (currentHeight + imageHeightArticle - (1.5 * imageHeightHeadline));
		
		//alert("H " + height);
		current.attr("box_h", currentHeight);
	});
	
	$(".collapsable").css("height", contentHeight + "em");
	$('.slider').toggle(
	function(ev) {
		stopBubbling = 0;
		openSlider(ev);		
	}, 
	function(ev) {
		stopBubbling = 0;
		closeSlider(ev);		
	});


});

function openSlider(ev)
{
	var slider, content, image;
	
	slider  = "#" + ev.target.id;
	image = content = slider;
	content = content.replace("S", "C");
	image = image.replace("S", "I");
	
	if (!stopBubbling) {
		var open_height = $(content).attr("box_h") + "px";
//		$(image).animate({"height": (imageHeightArticle + "px")}, {duration: "fast" });
		$(content).animate({"height": open_height}, {duration: "fast" });
		$(slider).click(function() { closeSlider(ev) });
		stopBubbling = 1;
		
	//	$(this).css("background", 'url("../gfx/collapsable-hide-i.png") no-repeat scroll 0 0 transparent');
		
		$(slider).hover(
			function () {
				$(slider).css("background", 'url("../gfx/collapsable-hide-a.png") no-repeat scroll 0 0 transparent');
			},
			function () {
				$(slider).css("background", 'url("../gfx/collapsable-hide-i.png") no-repeat scroll 0 0 transparent');
			}
		);


		$(image).css("height", "100px");
	}
}

function closeSlider(ev)
{
	var slider, content, image;
	
	slider  = "#" + ev.target.id;
	image = content = slider;
	content = content.replace("S", "C");
	image = image.replace("S", "I");

	content = slider;
	content = content.replace("S", "C");

	if (!stopBubbling) {
//		$(image).animate({"height": (imageHeightHeadline + "px")}, {duration: "fast" });
		$(content).animate({"height": (contentHeight + "em")}, {duration: "fast" });
		$(slider).click(function() { openSlider(); });
		stopBubbling = 1;

	//	$(this).css("background", 'url("../gfx/collapsable-show-i.png") no-repeat scroll 0 0 transparent');

		$(slider).hover(
			function () {
				$(slider).css("background", 'url("../gfx/collapsable-show-a.png") no-repeat scroll 0 0 transparent');
			},
			function () {
				$(slider).css("background", 'url("../gfx/collapsable-show-i.png") no-repeat scroll 0 0 transparent');
			}
		);

		$(image).css("height", "50px");
	}
}

function initZoom() {
	$(function() {
	//Set the default directory to find the images needed
	//by the plugin (closebtn.png, blank.gif, loading images ....)
	$.fn.fancyzoom.defaultsOptions.imgDir='/gfx/img-zoom/'; //very important must finish with a /
	//$.fn.fancyzoom.defaultsOptions.imgDir='http://www.ambassadewinkel.nl/gfx/img-zoom/'; //very important must finish with a /

	// Select all links in object with gallery ID using the defaults options
	$('#gallery a').fancyzoom(); 

	// Select all links with tozoom class, set the open animation time to 1000
	$('a.tozoom').fancyzoom({Speed:400,overlay:0.4});

	// Select all links set the overlay opacity to 80%
	//$('a').fancyzoom({overlay:0.8});
	
	//new rev > 1.2
	//apply fancyzoom effect on all image whose class is fancyzoom !!
	$('img.fancyzoom').fancyzoom();
});
}

/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function customer_carousel_initCallback(carousel) {
/*    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });  */

    jQuery('#customer-carousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#customer-carousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};




