/***********************************************
***  PRELOAD IMAGES & BACKGROUND  **************
************************************************/

$(document).ready(function() {
	if ($('body').hasClass('catalogue') == false)
		$("#wrapper").append('<div class="bgCover"></div>');
});


/***********************************************
***  BUTTON ACTIONS  ***************************
************************************************/

$(function(){
	$('#btnSubmit').click(function() {
		$('#submitID').val('contact');
		$('#contactForm').submit();
		return false;
	});

	$('#btnSignup').click(function() {
		$('#mailSubmitID').val('enews');
		$('#mailingListForm').submit();
		return false;
	});
});

/***********************************************
***  BUTTON ROLLOVER & PRELOAD  ****************
************************************************/

$(function(){
	// button rollover
	if ($('.imgBtn') != null) {
		$('.imgBtn').hover(function(){
				if(!$(this).is('.disabled'))
					$(this).attr("src", $(this).attr("src").replace(/^(.*?)(?:-hover)?(\..*?)$/i,'$1-hover$2'));
			},
			function(){
					if(!$(this).is('.disabled'))
						$(this).attr("src", $(this).attr("src").replace(/^(.*)-hover(\..*?)$/i, '$1$2'));
				});
	}
	// preload image rollovers
	if ($("img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']") != null) {
	    $("img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']").each(function(){
			    $("<img>").attr("src", $(this).attr("src").replace(/(btn-.*)(\..*?)/i, '$1-hover$2'));
		    });
	}
});

/***********************************************
***  COMPACT FORM (LABEL OVER INPUT)  **********
************************************************/

$(function(){
	$('form.compact input, form.compact select, form.compact textarea').focus(function(){
			$('label[for=' + $(this).attr('id') + ']').hide();
		});
	$('form.compact input, form.compact select, form.compact textarea').each(function(ele){
			if($(this).val().length > 0)
				$('label[for=' + $(this).attr('id') + ']').css({ display: "none" });
		});
	$('form.compact input, form.compact select, form.compact textarea').blur(function(){
			if($(this).val().length == 0)
				$('label[for=' + $(this).attr('id') + ']').show();
		});
	$('form.compact').removeClass('compact');
});

/***********************************************
***  EXTERNAL LINKS  ***************************
************************************************/

$(document).ready(function() {
	$("a[rel=external]").each(function() {
		$(this).addClass('external');
		$(this).attr({
			title: "Open this page in a new window",
			target: "_blank"
		});
	})
});

/***********************************************
***  EQUAL COLS  *******************************
************************************************/

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
		    tallest = thisHeight;
		}
	});
	if ($.browser.msie && $.browser.version.substring(0,1) === '6'){
		group.css('height',tallest);
	}
	else {
		group.css('min-height',tallest);
	}
}
$(function() {
	$(document).ready(function() {
	    equalHeight($(".resultsList li"));
	});
});

$(document).ready(function() {
	if ($.browser.msie && $.browser.version.substring(0,1) === '6'){
		$("#photoContainer").css('height',$("#main").height());
		$("#photo").css('height',$("#main").height());
	}
	else {
		$("#photoContainer").css('height',$("#main").height());
		$("#photo").css('height',$("#main").height());
	}
	$(".photoCover").css('height',$("#main").height());
});

/***********************************************
***  CUFON  ************************************
************************************************/

$(function() {
	Cufon.set('fontFamily', 'gill-sans').replace('h1.bannerHeader');
	Cufon.set('fontFamily', 'gill-sans').replace('.locationsList h2');
	Cufon.set('fontFamily', 'helvetica-neue').replace('#menu a',{ hover: true });
	Cufon.set('fontFamily', 'helvetica-neue').replace('.locationMenu li',{ hover: true, hoverables: { li: true } });
	Cufon.set('fontFamily', 'trash-hand').replace('.contactForm label');
    	Cufon.now();
});

/***********************************************
***  PROGRESSIVE ENHANCEMENT  ******************
************************************************/

$(document).ready(function() {
	$(".locationsList table tr:nth-child(2n-1)").addClass("dark");
	$(".locationsList table td:nth-child(2n)").addClass("number");
});

/***********************************************
***  TABS **************************************
************************************************/

$(function(){
	    $.fn.geeTabs = function(options) {
		    var settings = $.extend({}, $.fn.geeTabs.defaults, options);
		
		    this.each(function(index) {
			    $this = $(this);
			
			    var o = $.meta ? $.extend({}, settings, $this.data()) : settings;

			    $this.click(function() {
				    $(this).siblings('li.selected').removeClass('selected');
				    $(this).addClass('selected');
				    Cufon.refresh('.locationMenu li');
				    $(o.tabbedContentSelector + '.current').removeClass('current');
					$(o.tabbedContentSelector + ':eq(' + index + ')').addClass('current');
			    });
		    });
	    }
	
	    $.fn.geeTabs.defaults = {
		    tabbedContentSelector: '.locationsList li'
	    };
});

/***********************************************
***  SWF OBJECT  *******************************
************************************************/

swfobject.embedSWF("swf/catalogue_tile_01.swf", "catalogueBox", "220", "200", "8.0.0");
swfobject.embedSWF("swf/offer_01.swf", "offerBox", "287", "254", "8.0.0");
swfobject.embedSWF("catalogue/2010_04_Catalogue/catalogue.swf?pdfLocation=pdf/roger_david_suit_hire_catalogue_april_2010.pdf", "flashcontent", "800", "650", "8.0.0", "", {}, {wmode : "transparent"}, {});

swfobject.addDomLoadEvent(function() {
	$('.tiles').addClass('flashLoaded');
});


/***********************************************
*** ROTATING IMAGES HOMEPAGE *******************
************************************************/
var imgPath = 'images/photos/';
var imgFile = new Array('school-formal.jpg','personal.jpg','wedding.jpg','locations.jpg','pricing.jpg');
var imgAlt = new Array('School formal suit','Formal suit','Wedding suit','Formal suit','Stylish suit');
var x = 0;

function rotateImage()
{
	var displayImg = $('#displayImage');
	var transitionImg = $('#transitionImage');

	transitionImg.hide();
	var newImg = $('<img />')
	newImg.load(function() {
				var loadedImg = $(this);
				transitionImg.attr('src', loadedImg.attr('src'))
							 .attr('alt', imgAlt[x])
							 .fadeIn(1000, function() {
								transitionImg.hide();
								displayImg.attr('src', loadedImg.attr('src'))
										  .attr('alt', imgAlt[x]);
								setTimeout('rotateImage();',5000);
								x += 1;
								x = x > imgFile.length-1 ? 0 : x;
							 });
			});
	newImg.attr('src', imgPath + imgFile[x]);
							
}

$(function() {
	if ($('body').hasClass('home'))
		setTimeout('rotateImage();',5000);
});
