Cufon.replace("h1", { fontFamily: "Myriad" });
Cufon.now();
$("a[rel^='prettyPhoto']").prettyPhoto();
$("a.js-lightbox").lightBox();

// validate
$(".pageform").validate();

// new win
$("a[href*=twitter.com], a[href*=facebook.com]").each(function(){
   $(this).attr("target", "_blank"); 
});

// =============================================== THUMBNAILS ================================================= //
var thumb_container = $(".gallery .thumb-container")[0];
$(".gallery .thumb-container img").not(".active").css("opacity", "0.5");
var thumb_wrapper = $(".gallery .thumb-container ul")[0];
if($(".gallery .thumb-container ul").length) $(".gallery .thumb-container div").height(thumb_wrapper.clientHeight);
var i = 0;

// thumb scrolling
function scrollingTop(amount) {
//	i += 1;
//	if (i == 48) { thumb_container.scrollTop -= 18 }
//	else thumb_container.scrollTop -= 10;
//	var delay = "scrollingTop(" + amount + ")";
//	delay = setTimeout(delay, 10);
	//	if (i == 48) { clearTimeout(delay); i = 0; chckButtonsActivity(); }
	thumb_container.scrollTop -= 500;
	chckButtonsActivity();
}
function scrollingBottom(amount) {
//	i += 1;
//	if (i == 48) { thumb_container.scrollTop += 18 }
//	else thumb_container.scrollTop += 10;
//	var delay = "scrollingBottom(" + amount + ")";
//	delay = setTimeout(delay, 10);
	//	if (i == 48) { clearTimeout(delay); i = 0; chckButtonsActivity(); }
	thumb_container.scrollTop += 500;
	chckButtonsActivity();
}

// thumb buttons active/disable when scrolling
function chckButtonsActivity() {
	(thumb_container.scrollTop == 0) ? $(".gallery .scroll a.top img").attr("src", "../content/img/arrow-top-gray-pass.gif") : $(".gallery .scroll a.top img").attr("src", "../content/img/arrow-top-gray.gif");
	(thumb_container.scrollTop >= thumb_wrapper.clientHeight - thumb_container.clientHeight) ? $(".gallery .scroll a.bottom img").attr("src", "../content/img/arrow-bottom-gray-pass.gif") : $(".gallery .scroll a.bottom img").attr("src", "../content/img/arrow-bottom-gray.gif");
}
if ($(".gallery .scroll a.top").length) chckButtonsActivity();
$(".gallery .scroll a.top").click(function(e) { scrollingTop(thumb_container.scrollTop); e.preventDefault(); });
$(".gallery .scroll a.bottom").click(function(e) { scrollingBottom(thumb_container.scrollTop); e.preventDefault(); });

// action on click thumb
$(".gallery .thumb-container a").click(function(e) {
	e.preventDefault();
	$(".gallery .thumb-container img").removeClass("active");
	$(this).children().addClass("active");
	$(".gallery .thumb-container img").css("opacity", "1").not(".active").css("opacity", "0.5");
	var img_src = $(this).children().attr("src");
	if (!$(this).hasClass("press"))
	img_src = img_src.substring(0, img_src.length - 10) + ".jpg";
	$(".gallery .img-container img.active").animate({ "opacity": 0 }, 300, function() {
		$(this).hide().removeClass("active");
		$(".gallery .img-container img").each(function() {
			if ($(this).attr("src") == img_src) {
				$(this).css("opacity", 0).show().addClass("active");
				$(this).animate({ "opacity": 1 }, 300);
			}
		});
	});
});

// ========================================== SLIDES ROTATING ===================================================== //

var items_amount = $("ul.carousel li").length;
var items_amount1 = $(".slides-container img").length;
var item_num = 0;
var item_num1 = 0;
var delay = 0;

// home slide show
function homeShow() {
	old_slide = $("ul.carousel-slides li.active");
	old_slide.removeClass("active");
	$("ul.carousel-slides li").animate({ "opacity": "0.5" }, 300);
	setTimeout(function() {
		$("ul.carousel-slides").animate({ "marginLeft": cur_margin - 975 + "px" }, 500, function() {
			$("ul.carousel-slides li:first").remove().appendTo($("ul.carousel-slides"));
			$("ul.carousel-slides").css("marginLeft", cur_margin);
			old_slide.next().addClass("active");
			$("ul.carousel-slides li").animate({ "opacity": "1" }, 300);
		});
	}, 300);
	delay = setTimeout("homeShow()", 5000);
}

// home slides fade in/out
$("ul.carousel li:not('.active')").css("opacity","0");
function imgSlideShow() {
	$("ul.carousel li.active").animate({ "opacity": "0" }, 1000, function() {
		$("ul.carousel li.active").next().show();
		$(this).removeClass("active").hide();
		$(this).next().addClass("active").animate({ "opacity": "1" }, 1000);
		$(this).remove().appendTo($("ul.carousel"));
	});
	delay = setTimeout("imgSlideShow()", 7000);
}

// salon slide fade in/out
function slideShow() {
	$(".slides-container img").animate({ "opacity": "0" }, 300, function() {
		$(".slides-container img:eq(" + item_num1 + ")").addClass("show").animate({ "opacity": "1" }, 300);
	});
	(item_num1 == (items_amount1 - 1)) ? item_num1 = 0 : item_num1 += 1;
	$(".slider a").removeClass("active");
	$(".slider a:eq(" + item_num1 + ")").addClass("active");
	delay = setTimeout("slideShow()", 5000);
}

// salon slides paging
$(".slider div").html("");
for (var i = 0; i < $(".slides-container img").length; i++) {
	var temp = $(".slider div").html();
	(i == 0) ? active_class = "active" : active_class = "";
	$(".slider div").html(temp + "<a href='#' class='"+ active_class +"' id='"+i+"'>&nbsp;</a>");
}
// salon slides paging click
$(".slider a").click(function(e) {
	img_number = this.id;
	$(".slides-container img").animate({ "opacity": "0" }, 300, function() {
		$(".slides-container img:eq(" + img_number + ")").addClass("show").animate({ "opacity": "1" }, 300);
	});
	$(".slider a").removeClass("active");
	$(this).addClass("active");
	e.preventDefault();
	if(delay) clearTimeout(delay);
});

// home slides paging
$(".img-slider div").html("");
for (var i = 0; i < $(".slides-container img").length; i++) {
	var temp = $(".img-slider div").html();
	//(i == 0) ? active_class = "active" : active_class = "";
	$(".img-slider div").html(temp + "<a href='#' class='" + active_class + "' id='" + i + "'>&nbsp;</a>");
}
// home slides paging click
$(".img-slider a").live("click", function(e) {
	$(".img-slider a").removeClass("active");
	var a_id = this.id;
	$(".img-slider a").each(function() { if (this.id == a_id) $(this).addClass("active") });
	e.preventDefault();
	if (delay) clearTimeout(delay);
	$("ul.carousel li.active").animate({ "opacity": "0" }, 500, function() {
		$(this).removeClass("active");
		$("ul.carousel li:eq(" + a_id + ")").addClass("active");
		$("ul.carousel li:eq(" + a_id + ")").show().animate({ "opacity": "1" }, 500);
	});
});

// play/stop/prev/next home paging
$(".slider-arr a.slider-right").live("click", function(e) {
	e.preventDefault();
	clearTimeout(delay);
	$(".slider-arr a.slider-stop").removeClass("slider-stop").addClass("slider-play").text("PLAY");

	old_slide = $("ul.carousel-slides li.active");
	old_slide.removeClass("active");
	$("ul.carousel-slides li").animate({ "opacity": "0.3" }, 300);
	setTimeout(function() {
		$("ul.carousel-slides").animate({ "marginLeft": cur_margin - 975 + "px" }, 500, function() {
			$("ul.carousel-slides li:first").remove().appendTo($("ul.carousel-slides"));
			$("ul.carousel-slides").css("marginLeft", cur_margin);
			old_slide.next().addClass("active");
			$("ul.carousel-slides li").animate({ "opacity": "1" }, 300);
		});
	}, 300);
});
$(".slider-arr a.slider-left").live("click", function(e) {
	e.preventDefault();
	clearTimeout(delay);
	$(".slider-arr a.slider-stop").removeClass("slider-stop").addClass("slider-play").text("PLAY");

	old_slide = $("ul.carousel-slides li.active");
	old_slide.removeClass("active");
	$("ul.carousel-slides li").animate({ "opacity": "0.3" }, 300);
	setTimeout(function() {
		$("ul.carousel-slides").animate({ "marginLeft": cur_margin + 975 + "px" }, 500, function() {
			$("ul.carousel-slides li:last").remove().prependTo($("ul.carousel-slides"));
			$("ul.carousel-slides").css("marginLeft", cur_margin);
			old_slide.prev().addClass("active");
			$("ul.carousel-slides li").animate({ "opacity": "1" }, 300);
		});
	}, 300);
});
$(".slider-arr a.slider-stop").live("click", function(e) {
	e.preventDefault();
	$(this).removeClass("slider-stop").addClass("slider-play").text("PLAY");
	clearTimeout(delay);
});
$(".slider-arr a.slider-play").live("click", function(e) {
	e.preventDefault();
	$(this).removeClass("slider-play").addClass("slider-stop").text("STOP");
	homeShow();
});

/* lightbox */
if ($(".lightbox-my").length) {
	$(".gallery .img-container a").click(function(e) {
		e.preventDefault();
		$(".lightbox-my table div").html("");
		$(".gallery .thumb-container li").each(function() {
			$(".lightbox-my table div").html($(".lightbox-my table div").html() + $(this).html());
		});
		setTimeout(function() { $(".lightbox-my, .lightbox-overlap").show(); $(".lightbox-my table div").height($(".lightbox-my img.big").height()); }, 10);
		$(".lightbox-my img.big").attr("src", $(this).children("img").attr("src"));

	});

	$(".lightbox-my table div a").live("click", function(e) {
		e.preventDefault();
		$(".lightbox-my table div img").removeClass("active");
		$(this).children().addClass("active");
		$(".lightbox-my table div img").css("opacity", "1").not(".active").css("opacity", "0.5");
		var img_src = $(this).children().attr("src");
		if(!$(this).hasClass("press"))
		img_src = img_src.substring(0, img_src.length - 10) + ".jpg";
		$(".lightbox-my img.big").attr("src", img_src);
		//$(".lightbox-my img.big").animate({ "opacity": 0 }, 300, function() { $(".lightbox-my img.big").attr("src", img_src); setTimeout(function() { $(".lightbox-my img.big").animate({ "opacity": 1 }, 150); }, 300) });
	});

	$(".lightbox-my p a, .lightbox-my img.big, .lightbox-my a.close").click(function(e) {
		e.preventDefault();
		$(".lightbox-my img.big").attr("src", "");
		$(".lightbox-my, .lightbox-overlap").hide();
	});
}

// =================================================== PAGE LOAD ==================================================== //

var content_height;
var IE7 = (navigator.appVersion.indexOf("MSIE 7.") == -1) ? false : true;

if (!$(".home-page").length && IE7) {
	tdHeight = $("table#body").height() - $("#header").height() - $("#footer").height();
	$("table#body td.middle-part").height(tdHeight);
	function resizeToColumn() {
		$("table#body td.middle-part").height("auto");
		tdHeight = $("table#body").height() - $("#header").height() - $("#footer").height();
		$("table#body td.middle-part").height(tdHeight);
	}
	$(window).resize(resizeToColumn);
}

$(window).load(function() {
	if ($(".salons-page").length) delay = setTimeout("slideShow()", 3000);
	if ($(".home-page").length) {
		var cur_margin;
		homepageHeight();
		//homepageWidth();
		if ($("ul.carousel").length) delay = setTimeout("imgSlideShow()", 5000);
		if ($("ul.carousel-slides").length) delay = setTimeout("homeShow()", 7000);
		$(window).resize(homepageHeight);
		//$(window).resize(homepageWidth);
	}
	//if ($(".gallery-page").length) {
	
	//}
});

$(document).ready(function() {
	content_height = $("#content").height();
	$(".rotation .rotation-container p").each(function(){
		this.innerHTML = this.innerHTML.replace(/&nbsp;/gi, " ").replace(/<br>/gi, " ");
	});
});

// home slide positioning
function homepageWidth() {
	doc_width = document.documentElement.clientWidth;
	cur_margin = -975 + ((doc_width - 975) / 2);
	if (doc_width <= 975) cur_margin = 0;
	$("ul.carousel-slides").css("marginLeft", cur_margin)
}

// full page height
function homepageHeight() {
	_content_ = $("#content");
	_document_ = document.documentElement.clientHeight;
	_header_ = $("#header").height();
	_footer_ = $("#footer").height();
	_content_height_ = _document_ - _header_ - _footer_;
	//alert(_content_height_ + "; " + content_height);
	if (_content_height_ > content_height) {
		_content_.height(_content_height_);
		var marg = (_content_height_ - $("#content > .container").height()) / 2;
		if ($(".home-page").length) marg = "0";
		$("#content > .container").css("paddingTop", marg + "px");
	}
	else { _content_.height(content_height); $("#content > .container").css("paddingTop", "0"); }
	if ($(".home-page").length) {
		if (_content_height_ > content_height)
			$("#content ul li .slides-container").height(_content_height_);
		else $("#content ul li .slides-container").height(content_height);
		if (_content_height_ > content_height)
			$("#content .gallery .img-container").height(_content_height_);
		else $("#content .gallery .img-container").height(content_height);
		if (_content_height_ > content_height)
			$("#content .gallery .thumb-container").height(_content_height_ - 90);
		else $("#content .gallery .thumb-container").height(content_height - 90);
	}
}

/* prices */
$(".prices-display").live("click", function(e) {
	e.preventDefault();
	$(this).text("BACK TO SALON").removeClass("prices-display").addClass("salon-display");
	$(".rightcol .salon-img").animate({ "opacity": "0" }, 500, function() {
		$(".rightcol .salon-img").hide();
		$(".prices-list").css("opacity", "0").show();
		$(".prices-list").animate({ "opacity": "1" }, 500);
	});
});
$(".salon-display").live("click", function(e) {
	e.preventDefault();
	$(this).text("SALON PRICES").removeClass("salon-display").addClass("prices-display");
	$(".rightcol .prices-list").animate({ "opacity": "0" }, 500, function() {
		$(".rightcol .prices-list").hide();
		$(".salon-img").css("opacity", "0").show();
		$(".salon-img").animate({ "opacity": "1" }, 500);
	});
});
$(".beauty-display").live("click", function(e) {
	e.preventDefault();
	$(this).text("BACK TO SALON").removeClass("beauty-display").addClass("salon1-display");
	$(".rightcol .salon-img").animate({ "opacity": "0" }, 500, function() {
		$(".rightcol .salon-img").hide();
		$(".beauty-list").css("opacity", "0").show();
		$(".beauty-list").animate({ "opacity": "1" }, 500);
	});
});
$(".salon1-display").live("click", function(e) {
	e.preventDefault();
	$(this).text("BEAUTY PRICES").removeClass("salon1-display").addClass("beauty-display");
	$(".rightcol .beauty-list").animate({ "opacity": "0" }, 500, function() {
		$(".rightcol .beauty-list").hide();
		$(".salon-img").css("opacity", "0").show();
		$(".salon-img").animate({ "opacity": "1" }, 500);
	});
})

// hob people
$(".directors-area, .team-area").click(function() {
	_this = this;
	this_ = (this.className == "team-area") ? "#directors-area" : "#team-area";
	$(this_).slideUp(500, function() {
		$("#" + _this.className).slideDown(500);
	});
})

//awards
$(window).load(function() {
	//$(".awards-wrapper").jScrollPane({ showArrows: true, wheelSpeed: 100 });
})

//faq
$(".faqs p, .faqs ul, .faqs ol").hide();
$(".faqs strong").toggle(function() { $(this).next().next().slideDown(500); }, function() { $(this).next().next().slideUp(500); })

// js-items
$("a[class^=js-item]").click(function(e) {
	e.preventDefault();
	$(this).parent().addClass("active").siblings().removeClass("active"); ;
	$(".js-item").hide();
	$("#" + this.className).show();
	resizeToColumn();
});

// rotation
$(".rotation .rotation-container p:not('.main'), .rotation1 .rotation-container p:not('.main')").css("opacity", 0);
$(".rotation .rotation-container p, .rotation1 .rotation-container p").live("mouseover", function() {
	$(this).children("b, strong").show();
});
$(".rotation .rotation-container p, .rotation1 .rotation-container p").live("mouseout", function() {
	$(this).children("b, strong").hide();
});
function rotation() {
	currImg = $(".rotation .rotation-container p.main");
	currImg.animate({ "opacity": "0" }, 300, function() {
		currImg.next("p").addClass("main").animate({ "opacity": "1" }, 300);
		currImg.children("b, strong").hide();
		currImg.removeClass("main").remove().appendTo($(".rotation .rotation-container"));
	});
	rot_delay = setTimeout("rotation()", 3000);
}
function rotation1() {
	currImg1 = $(".rotation1 .rotation-container p.main");
	currImg1.animate({ "opacity": "0" }, 300, function() {
		currImg1.next("p").addClass("main").animate({ "opacity": "1" }, 300);
		currImg1.children("b").hide();
		currImg1.removeClass("main").remove().appendTo($(".rotation1 .rotation-container"));
	});
	rot_delay1 = setTimeout("rotation1()", 3000);
}
rot_delay = setTimeout("rotation()", 3000);
rot_delay1 = setTimeout("rotation1()", 1500);
$(".rotation-container p").each(function() {
	$(".img-circles").html($(".img-circles").html() + "<a href='#'>&nbsp;</a>");
});
$(".img-circles a").live("click", function(e) {
	e.preventDefault();
	$(".img-circles a").removeClass("active");
	$(this).addClass("active");
	index = $(".img-circles a").index(this);
	clearTimeout(rot_delay);
	$(".rotation-container p").removeClass("main");
	$(".rotation-container p")[index].className = "main";
	$(".rotation-container p.main").css("opacity", "1");
});
$(".img-circles").css("opacity", 0.7);

// right click
$(function() {
	$(this).bind("contextmenu", function(e) {
		e.preventDefault();
	});
});

// find salon
$(".searching .search-bg .txt-search").focus(function(){this.value="";});
$(".searching .search-bg .btn-search").click(function(){
	postal_code = $(".searching .search-bg .txt-search").attr("value").toUpperCase();
	switch(postal_code){
		case "W1U 7DE": window.location.href="/salons/london.php"; break;
		case "HA6 2QB": window.location.href="/salons/northwood.php"; break;
		case "HP6 5DR": window.location.href="/salons/amersham.php"; break;
		case "WD7 7LB": window.location.href="/salons/radlett.php"; break;
		case "EN5 5UZ": window.location.href="/salons/barnet.php"; break;
		case "WD3 1AN": window.location.href="/salons/rickmansworth.php"; break;
		case "WD23 1GE": window.location.href="/salons/bushey.php"; break;
		case "HA4 8JB": window.location.href="/salons/ruislip.php"; break;
		case "NW1 7BY": window.location.href="/salons/camden.php"; break;
		case "N14 5PA": window.location.href="/salons/southgate.php"; break;
		case "WD6 3SB": window.location.href="/salons/elstree.php"; break;
		case "AL1 3YJ": window.location.href="/salons/albans.php"; break;
		case "HA5 4HR": window.location.href="/salons/hatch_end.php"; break;
		case "HA7 4AL": window.location.href="/salons/stanmore.php"; break;
		case "LS1 6DL": window.location.href="/salons/leeds.php"; break;
		case "NW11 7TJ": window.location.href="/salons/temple_fortune.php"; break;
		case "IG10 1AH": window.location.href="/salons/loughton.php"; break;
		case "NW6 1UR": window.location.href="/salons/west_hampstead.php"; break;
		case "NW7 3LL": window.location.href="/salons/mill_hill.php"; break;
		case "N20 9HH": window.location.href="/salons/whetstone.php"; break;
		default: alert("No HOB Salon found in " + postal_code); break;
	}
})

// book-online
$(".book-online a").click(function(e){
	e.preventDefault();
	$(".book-online-wrapper").show(500);
});
$(".book-online-wrapper a:last-child").click(function(e){
	e.preventDefault();
	$(".book-online-wrapper").hide(500);
});
$(".book-online-wrapper a:first").click(function(e){
	this.href = $(".book-online-wrapper select").attr("value");
	$(".book-online-wrapper").hide(500);
});