$(document).ready(function(){
						   
	//stick footer
	/*
	var currentHeight =  $("#content").height();
	window.onload = function() {setContentHeight(currentHeight);}
	window.onresize = function() {setContentHeight(currentHeight);}
	*/
	
	//slideshow
    (function(){
        var slideshow = $('#slideshow');
        $('<span id="slideshow-flower"></span>').insertAfter(slideshow);

        if ($('body').is('#home-page') && $('#slideshow').length) {
            var slides = 6;
            var img;
            for (var i = 1; i <= slides; i++) {
                img = $('<img>', {
                    src: '/images/masthead/' + i + '.jpg',
                    timeout: 4000,
                    speed: 500,
                    height: 269,
                    width: 666
                });
                slideshow.append(img);
            }
            slideshow.cycle({fx: 'fade'});
        }
    })();
	
	//language selector
	if($("div#language ul").length>0) {
		$("div#language").click(function(){$("div#language ul").slideToggle("slow");});
	}
	
	if($("input#keywords").length>0) {
		$("input#keywords").click(function(){  
		   if($(this).val()=='Search') {$(this).val('');} 
	   	});	
	}

        if($('ul#spa-list').length > 0) {            
            var optionTexts = [];
            var headings = [];
            var t=0;
            var t_elem;
            $("ul#spa-list > li").each(function () {
                if ( $(this).outerHeight() > t ) {
                    t_elem=$(this);
                    t=t_elem.outerHeight();
                }
            });
            $("ul#spa-list > li").each(function() {
                cl = " class=\"selected\"";
                if($(this).index()>0)
                    cl = "";
                headings = headings + '<a href="'+$(this).index()+'"'+cl+'>' + $(this).find(">:first-child").text() + '</a>';
                optionTexts.push($(this).html());                
            });            
            var menubar = '<h2 class="menuBar">'+ $("ul#spa-list li:first > h2").text()+ '</h2>';            
            $("ul#spa-list").before(menubar).hide();
            $("h2.menuBar").after('<div id="selectPanel">' + headings + '</div>');

           $("ul#spa-list").after('<div id="appendedContent"></div>');
           //$('#appendedContent').height(t).html(optionTexts[0]);
           $('#appendedContent').html(optionTexts[0]);
           $('#appendedContent h2').hide();


            $("h2.menuBar").click(function(event){
                event.preventDefault();
                event.stopPropagation();
                $('#selectPanel').slideToggle('fast');
            });
            
            $("#selectPanel a").click(function(event){
                event.preventDefault();
                event.stopPropagation();
                $("#selectPanel a").removeClass('selected');
                $(this).addClass('selected');                
                var hrefArr = $(this).attr('href').split('/');
                var id = hrefArr[hrefArr.length-1];
                var opt = optionTexts[id];
                $("#selectPanel").slideToggle('fast',function(){
                    $('#appendedContent').html(opt).children().fadeIn('slow');
                    $("h2.menuBar").text($('#appendedContent > h2').text());
                    $('h2.menuBar').append('<span>pick a category...</span>');
                    $('#appendedContent h2').hide();
                });
            });
           /* $("h2.menuBar").hover(function(){
                $(this).addClass('menuBarOver');
            },function(){
                $(this).removeClass('menuBarOver');
            });

            $("#selectPanel").hover(function(){
                $("h2.menuBar").addClass('menuBarOver');
            },function(){
                    //setTimeout(function() {
                       $(this).slideUp('fast');
                       $("h2.menuBar").removeClass('menuBarOver');
                   //}, 500);
            });*/
            $('h2.menuBar').append('<span>pick a category...</span>');
        }





	//our products
	if($("dl#our_product").length>0) {
                
		$("dl#our_product dt").addClass("jsStyled");
		$("dl#our_product dd").hide();
		if($("div#our_product_info").html()=='') {
			$("div#our_product_info").html($("dl#our_product dd:first").html());
			$("dl#our_product dt").css("color","#3933ba");
			$("dl#our_product dt:first").css("color","#161c45"); //selected
		}
		
		$("dl#our_product dt").click(function(){
			var newTxt = $(this).next().html();	
			$("dl#our_product dt").css("color","#3933ba");
			$(this).css("color","#161c45"); //selected	
			$("div").queue(function () {
				$("div#our_product_info").hide();
				$("div#our_product_info").dequeue();		
			});			
			$("div").queue(function () {
				
				$("div#our_product_info").html(newTxt);
				$("div#our_product_info").dequeue();
			});		
			$("div").queue(function () {
				$("div#our_product_info").fadeIn("slow");
				$("div#our_product_info").dequeue();
			});		
			return false;
		});
	}
	
	if($("ul#our_product_range_info").length>0) {
		

		$("ul#our_product_range_info li").hide();
		$("ul#our_product_range_info li:first").show();
		$("ul#our_product_range_info li:first li").show();	
	
		$(window).bind('load', function() {
			var preload = new Array();
			preload[0] = "/images/flowers/new/crystalesscent.png";
			preload[1] = "/images/flowers/new/everesscent.png";
			preload[2] = "/images/flowers/new/luminesscent.png";
			preload[3] = "/images/flowers/new/pearlesscent.png";
			preload[4] = "/images/flowers/new/pureesscent.png";
			preload[5] = "/images/flowers/new/quintesscent.png";
			preload[6] = "/images/flowers/new/rejuvenesscent.png";
			var img = document.createElement('img');
			$(img).bind('load', function() {
				if(preload[0]) {
					this.src = preload.shift();
				}
			}).trigger('load');
		});
		
		
		$("ul#our_product_selector li a").click(function(){
			var imgFile = "/images/flowers/new/" + $(this).text().toLowerCase() + ".png";			
			var selId = $(this).parent().attr("id");								 
			var numId = selId.substring(4);
			
			$("ul#our_product_selector li a").removeClass("selected");
			$("ul#our_product_selector li#sel_"+numId+" a").addClass("selected");
						
			$("img").queue(function () {
				$("img#prod-range-image").fadeOut(100);
				$("ul#our_product_range_info li").fadeOut("fast");
				$(this).dequeue();
			});
			$("img").queue(function () {
				$("img#prod-range-image").attr("src",imgFile);
				$(this).dequeue();
			});
			$("img").queue(function () {
				$("img#prod-range-image").fadeIn(700);
				$("ul#our_product_range_info li#info_"+numId).fadeIn("slow");
				$("ul#our_product_range_info li#info_"+numId+' li').fadeIn("slow");
				$(this).dequeue();
			});
			return false;
		});
		
		$("ul#our_product_selector li:first a").click();
		
	}
	
	
	if($("a.lightbox").length > 0) {
		$(function() {
			$('a.lightbox').lightBox({
			fixedNavigation:false,
			imageLoading: '/images/lightbox/lightbox-ico-loading.gif',
			imageBtnClose: '/images/lightbox/lightbox-btn-close.gif',
			imageBtnPrev: '/images/lightbox/lightbox-btn-prev.gif',
			imageBtnNext: '/images/lightbox/lightbox-btn-next.gif'
			});
		});	
	}
	
	if($("select#view-max").length>0) {
		if($("select#view-max").children().length==1){
			$("select#view-max").attr("disabled","disabled");	
		}
	}
	
	
	if($("ul.moreinfo a.spa-more-info").length > 0) {	
		$("a.spa-enquiry").click(function(){
			$(this).parent().parent().prev().prev().children("div.enquiry").slideToggle();								
			return false;
		});
		
	}
	

});

function setContentHeight(currentHeight) {
	
	var setHeight = currentHeight;
	
	var resetHeight = $(window).height()-489;
	if(setHeight<resetHeight)
		setHeight = resetHeight;
	$("#content").height(setHeight);
	/*IE7 want to put 5px below the container - don't know why - this kind of fixes it*/
	if ( $.browser.msie ) {
		var ieVersion = parseInt(jQuery.browser.version);
		if(ieVersion==7) 
			$("#container").css("padding-bottom", "5px");
	}
	
}

function jumpto(selObj){
  eval("parent.location='"+selObj.options[selObj.selectedIndex].value+"'");
}



