$(document).ready(function() {
	$("#nav ul").css({display: "none"}); // Opera Fix
	
	//For main nav rollovers and dropdowns.
	$("#nav li:not(:first-child)").hover(
		function(){
			var org = $(this).find("img").attr("src");
			org = org.split(".")[0];
			$(this).find("img").attr({src: "" + org + "_over.jpg"});
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(); },
		function(){
			var org = $(this).find("img").attr("src");
			if(org != undefined){
				org = org.split("_over");
				if (org.length == 1)
					org = org[0].split(".");
				org = org[0];
				$(this).find("img").attr({src: "" + org + ".jpg"});
			}
			$(this).find('ul:first').css({visibility: "hidden"});
	});
	
	
	/*Lightbox: see Colorbox documentation at http://colorpowered.com/colorbox/
		
		Add rel="lightbox" to the anchor tag to initiate lightbox. There is also an enlarge icon that appears on hover.
		Example for this site:
		
		<a href="images/product1_med.jpg" rel="lightbox">
					<img src="images/f_roses.jpg" width="223" height="228" align="absbottom" />
					<img src="images/i_magnify.png" width="24" height="24" align="absbottom" class="enlargeIcon" />
		</a>
	*/
	
	if ($('a[rel="lightbox"]').length)
		$('a[rel="lightbox"]').colorbox({opacity:.5, rel:'nofollow'});
		
	//For HTML lightbox
	if ($('a[rel="lightbox_iframe"]').length)
		$('a[rel="lightbox_iframe"]').colorbox({width:650, height:300, iframe:true, rel:'nofollow'});

	
	
	$('.lightboxCont').hover(
		function(){
			$(this).find('.enlargeIcon').css({visibility: "visible"})
		
		},
		function(){
			$(this).find('.enlargeIcon').css({visibility: "hidden"})
		}	
	);
	
//	$(".itemTable tr").each(function() {
//		$(".itemCell > div:first-child", this).setAllToMaxHeight();
//	});
	
	$('#popupDatepicker').datepick({changeMonth: false, showTrigger: '#calImg'});
	$('#deliveryDate').datepick({showTrigger: '#calImg'});
	
	slideShow();
	
	$('.watermark').focus(function() {
		var $this = $(this);
		if (!$this.data('watermark')) {
			$this.data('watermark', $this.val());
			$this.val('');
			$this.removeClass('watermark');
		}
	}).blur(function() {
		var $this = $(this);
		if (!$this.val()) {
			$this.val($this.data('watermark'));
			$this.data('watermark', null);
			$this.addClass('watermark');
		}
	});
	
	$('select[name="language"]').change(function () {
		var lang = $(this).val();
		if (lang == "English")
			document.location.href = "/";
		else
			document.location.href = "/" + lang;
	});
});


function slideShow(){
	 $('#slideshowImages').cycle({
        fx:      'fade',
        timeout:  9000,
        pager:   '#slideshowControls'
    });
	 
	  $('#testimonials').cycle({
        fx:      'fade',
        timeout:  8000
    });
}

$.fn.setAllToMaxHeight = function(){
	return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
}
