jQuery(document).ready(function(){
	if(jQuery(".thumbs:first .active:first").length == 0)
		jQuery(".thumbs:first li:first").addClass("active");
	jQuery(".thumbs:first li").click(function(e){
		e.preventDefault();
		jQuery.each(jQuery(".thumbs:first li"), function(i, val) {
			if(jQuery(val).hasClass("active"))
				jQuery(val).removeClass("active");
	    });
	 	jQuery(this).addClass("active");
		var img = jQuery(this).children("a");
		jQuery("#big-image").attr("src",jQuery(img).attr("href"));
	});
	
	jQuery("#gal-next").click(function(e){
		e.preventDefault();
		var next_li;
		if(jQuery(".thumbs:first .active:first").is(':last-child'))
			next_li = jQuery(".thumbs:first li:first");
		else
			next_li = jQuery(".thumbs:first .active:first").next();
		var img = $(next_li).children("a");
		jQuery("#big-image").attr("src",jQuery(img).attr("href"));
		jQuery.each(jQuery(".thumbs:first li"), function(i, val) {
			if(jQuery(val).hasClass("active"))
				jQuery(val).removeClass("active");
	    });
	 	jQuery(next_li).addClass("active");
		
	});
	
		jQuery("#gal-prev").click(function(e){
			e.preventDefault();
			var prev_li;
			if(jQuery(".thumbs:first .active:first").is(':first-child'))
				prev_li = jQuery(".thumbs:first li:last");
			else
				prev_li = jQuery(".thumbs:first .active:first").prev();
			var img = $(prev_li).children("a");
			jQuery("#big-image").attr("src",jQuery(img).attr("href"));
			jQuery.each(jQuery(".thumbs:first li"), function(i, val) {
				if(jQuery(val).hasClass("active"))
					jQuery(val).removeClass("active");
		    });
		 	jQuery(prev_li).addClass("active");

		});
	
	//Larger thumbnail preview 

	$("#colours ul li").hover(function() {
		$(this).css({'z-index' : '10'});
		$(this).find('img').addClass("hover").stop()
			.animate({
				marginTop: '-50px', 
				marginLeft: '-95px', 
				top: '50%', 
				left: '50%', 
				width: '196px', 
				height: '97px'
			}, 
			{
				duration:400, 
				complete:function(){
					var li = $(this).parent().get(0);
					$(li).append("<span>"+$(this).attr("alt")+"</span>");
				}
			});
		} , function() {
		$(this).css({'z-index' : '0'});
		var mTop = '0';
		var mLeft = '0';
		if($.browser.msie){
			if($.browser.version=="6.0" || $.browser.version=="7.0"){
				mLeft = '15px';
			}
		}
		$(this).find('img').removeClass("hover").stop()
			.animate({
				marginTop: mTop, 
				marginLeft: mLeft,
				top: '0', 
				left: '0', 
				width: '71px', 
				height: '37px'
			},400);
			var li = $(this).parent().get(0);
			$(li).find("span").remove();
	});
	
	//form input handeling hidden labled	
	$("input[type='text']").focus(function() {
		if ($(this).attr("value") == $(this).attr("rel")){
			$(this).attr("value", "");
		}
	});
	
	$("input[type='text']").blur(function() {
		if ($(this).attr("value") == "")
			{
				var val = $(this).attr("rel");
				$(this).attr("value", val);
			}
	});
	
	$("input[type='text']").load(function() {
		if ($(this).attr("value") == "")
			{
				var val = $(this).attr("rel");
				$(this).attr("value", val);
			}
	});
	
	$("textarea").focus(function() {
		$(this).text("");
	});
	
	//Lightbox for main gallery
	$('a.lightbox').lightBox();
	$('a.lightbox1').lightBox();
	$('a.lightbox2').lightBox();
	$('a.lightbox3').lightBox();
	$('a.lightbox4').lightBox();
	$('a.lightbox5').lightBox();
	$('a.lightbox6').lightBox();
	$('a.lightbox7').lightBox();
	$('a.lightbox8').lightBox();
	$('a.lightbox9').lightBox();
	$('a.lightbox10').lightBox();
	$('a.lightbox11').lightBox();
	$('a.lightbox12').lightBox();
	
	$(".range a").mouseover(function() {
		$(".hidden", this).stop(true, true).show();
	});
	$(".range a").mouseout(function() {
		$(".hidden", this).fadeOut(3500);
	});
	
	//external link
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
	//home page slide show
	$('.slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		pause: 1,
		delay: -2000,
		timeout: 3000
	});
});