$(function () {

	// home page article cycle
	if ($('body#home').length > 0) {
		$('#articles').cycle({ 
			fx:     'fade', 
			speed:    500, 
			pause: true,
			timeoutFn: calculateTimeout 
		}); 
	}    
 
	function calculateTimeout(currElement, nextElement, opts, isForward) { 
		var index = opts.currSlide; 
		if ($('.a-item').length > 1)
			var to = ($('a.a-link').eq(index).attr('rel')*1000);
		else 
			var to = 5000
		return to;
	} 
		
	// clear search message
	$('#header #clearSearch').click(function() {
		$(this).blur();
		$('#header input#keywords').val('').focus();
		return false;
	});
	$('#header input#keywords').bind("focus", function() {
		if ($('#header input#keywords').val() == "Enter Search Keywords" )
			$('#header input#keywords').val('').focus();										
	});
	
	/*$('#search_form button').bind("click", function() {
		$('#search_form').submit();
	});*/
	
	
	
	//equalise quicklink heights
	if ($('.ql-top').length > 0 ) {
		var quicklinks = new Array();
		$('.ql-top').each( function() {
			quicklinks.push($(this).height())
		});
		var biggest = 0;
		for (x=0;x<quicklinks.length;x++) {
			if (quicklinks[x] > biggest) {
				biggest = parseInt(quicklinks[x]);
			}
		} 
		$('.ql-top').height(biggest);
		if ($('body#home').length > 0 ) {
			//adjust height for quicklinks -- ONLY ON HOMEPAGE
			var leftheight = $('div#left-col').height();
			var mainheight = $('div#main').height();
			//var quicklinksheight = $('div#quicklinks').height();
			if (mainheight < leftheight) {
				var add = leftheight - mainheight;
				$('div#quicklinks').css('margin-top', add);
			} else if (leftheight < mainheight ) {
				var add = mainheight - leftheight;
				var colheight = $('div.col-menu-top:first').height();
				$('div.col-menu-top').height(colheight + add + 0);
			}
		}
	} 	
	
	// get rid of double lines
	$('.col-top, .ql-top, .ql-bottom').each(function() {
		var ha = $(this).height();
		if (ha % 2 == 0 ) {	
			$(this).height(ha-1);
		} 
	});

	// append raquo to links
	$('a.product-more').append('&nbsp;&raquo;');
	$('a.product-more').attr('target', '_blank');

	//focus form fields
	/*$('input:text, textarea').focus(function() {
		$(this).addClass('input-focus');
	});
	$('input:text, textarea').blur(function() {
		$(this).removeClass('input-focus');
	}); */
	
	$('input:text, textarea').focus(function() {
		$(this).addClass('input-focus');
		$(this).parents('span').eq(0).addClass('input-focus');
	});
	$('input:text, textarea').blur(function() {
		$(this).removeClass('input-focus');
		$(this).parents('span').eq(0).removeClass('input-focus');
	});
	
});
