/**
 * JavaScript Script - jscript_1common.js
 *
 * @package templateSystem
 * @copyright 2011 Tom Wilkin
 * @version 1.0
 */

// globals
var initialSearchText = "Enter search keywords here";

$(document).ready(function( ) {
	// hide all the sub categories initially
	$("#categoriesContent .g4g_sub_category").each(function( ) {
		$(this).css("display", "none");
	});
	
	// initialise link expansion
	$("#categoriesContent .g4g_category_parent a").each(function( ) {
		$(this).click(function(e) {
			// check if this is a sub-category
			if($(this).hasClass("category_sub"))
				return true;
				
			// if this is selected then make it clickable
			if($(this).hasClass("g4g_category_selected"))
				return true;
			
			// check if this is already open
			if($(this).parents("div").children(".g4g_sub_category")
					.css("display") != "none")
			{	
				// click the link
				return true;
			} else {
				// disbale the link
				e.preventDefault( );
			
				// collapse all the others
				$("#categoriesContent .g4g_sub_category").each(
					function( ) {
						if($(this).css("display") != "none") {
							$(this).slideToggle( );
						}
					}
				);
			
				// show this one
				$(this).parents("div").children(".g4g_sub_category")
						.slideToggle( );
			}
		}); // end .click
	});
	
	// header search box
	$("input[name='keyword']").attr("value", initialSearchText);
	
	// clicking the box clears it
	$("input[name='keyword']").each(function( ) {
		$(this).focus(function( ) {
			// if it's the initial text, clear
			if($(this).attr("value") == initialSearchText)
				$(this).attr("value", "");
		}); // end .focus
	}); // end .each
	
	// moving, re-enters it
	$("input[name='keyword']").each(function( ) {
		$(this).blur(function( ) {
			// if it's blank fill it
			if($(this).attr("value") == "")
				$(this).attr("value", initialSearchText);
		}); // end .blur
	}); // end .each
	
	// clicking links in the footer/links has target="_blank"
	$("#footer #siteinfoLegal a").attr("target", "_blanK");
	$("#leftLinks a").attr("target", "_blank");
}); // end .ready

