//
// DOM LOAD FUNCTIONS
// Amended By		Date (YYYY/MM/DD)
// david@skywire	2008.07.07
//
$(document).ready(function(){
	
	
	// set up home page slide/fade show
	$('#homeSlide').cycle({ 
	    fx:      'fade', 
	    speed:    1, 
	    timeout:  5000 
	});
	
	
	// find all the input elements with title attributes
	$('input[title!=""]').hint();
	
	
	// handling product description
	var maxDescHeight = 80; // longest the desciption can be in px before it is cut off and replace with 'view more'
	var descHeight = $("#pDesc div").height();
	if (descHeight > maxDescHeight) {
		// expand/collapse product description
		$('a#expandDesc, a#collapseDesc').click(function() {
			$("#prodContent").toggleClass("showFullDesc"); // toggle class to show full description
			return false;
		});
	} else {
		$('#pDesc a#expandDesc').hide();
		$('#pDesc').css("height","auto");
	}
	
	
	// expand/collapse forward to a friend button and form
	$('p#pFor').show();
	$('p#pFor a, a#closeFriend').click(function() {
		$("#Ffriend").toggle(); // toggle to show form
		$("div.pOpt").toggle(); // toggle to hide input selects (really just for ie6 incorrect implementation of select boxes)
		return false;
	});
	
	
	// FLASH ZOOM IMAGE button
	$("#pZoom a")
		.click(
			function(){
				zoomButton();
				return false;
			}
		)
	// zoom thumbs
	$(".altLinks a")
		.each(
			function(){
				$(this).bind (
					"click",
					function(){
						s = $(this).find("img").attr("title");
						sB = $(this).attr("href");
						changeImage(s, sB);
						return false;
					}
				)
			}
		)
	
	
	// FORM CHECKING - TBD
	function checkForm(){
	}
	
	
	// FORWARD THANKS FADE
	$("#friendThanks").vkfade("C1B5BC");
	
	
	// POPUP BOX
	$("a.popUp")
		.click(
			function(){
				// grab href of link
				var addr = $(this).attr("href");
				// concatenate an id for the ajax to return
				if (addr.indexOf('terms') > 0) {
					addr = addr + " #termsContent";
				} else if (addr.indexOf('sizing') > 0) {
					addr = addr + " #sizingContent";
				}
				// create a div to put the popup into
				$("<div id=\"popUpHolder\"></div>").appendTo("#primaryContent");
				// ajax load the content into the div
				$("#popUpHolder").load(addr,function(){
					// add close popUpLink and close action
					$("<a id=\"closePopUp\" href=\"#\">Close</a>").appendTo("#popUpHolder").click(
						function(){
							$("#popUpHolder").remove();
							return false;
						}
					);
				 });
				return false;
			}
		)

	

}); 