//Shadowbox.loadSkin("classic", "http://www.lasik.co.nz/modules/mod_ninja_shadowbox/ninja_shadowbox/js/skin");
//Shadowbox.loadLanguage("en", "http://www.lasik.co.nz/modules/mod_ninja_shadowbox/ninja_shadowbox/js/lang");
//Shadowbox.loadPlayer(["img","iframe","html"], "http://www.lasik.co.nz/modules/mod_ninja_shadowbox/ninja_shadowbox/js/player");
//window.onload = Shadowbox.init;

jQuery(document).ready(function($){
	
	/* ----------------
	 * Change Font Size
	 * Simon Winter
	 * 31 March 2010
	 * ----
	 * Allow the user to change font sizes - lock them down to specific classes
	 * so that we can control the increments.
	 * ---------------- */
	var originalFontSize = $('#content').css('font-size');	
	var i = 2;
	var classes = Array("smaller","small","normal","big","bigger");
	
	// Increase Font Size
  	$(".increasefont").click(function(){
		if(i<classes.length-1) {
			$("#content").removeClass().addClass(classes[++i]);
			$(".decreasefont").removeClass("disabled");
		}
		
		if(i==classes.length-1) {
			$(".increasefont").addClass("disabled");
			$(".decreasefont").removeClass("disabled");
		}
			
    	return false;
  	});
	
  	// Decrease Font Size
  	$(".decreasefont").click(function(){
		if(i>0) {
			$("#content").removeClass().addClass(classes[--i]);
			$(".increasefont").removeClass("disabled");
		}
			
		if(i==0) {
			$(".decreasefont").addClass("disabled");
			$(".increasefont").removeClass("disabled");
		}
		
    	return false;
  	});
	
	

  
  	/* ------------------
	 * Go to top of page.
	 * ------------------
	 * Simon Winter
	 * 23 March 2010
	 * ----
	 * When activated, the go to top link should slide up to
	 * the top of the page.
	 * ----------------- */
  	$("#topLink").click(function() {
		$("html,body").animate( { scrollTop: 0 }, 'slow','', function() {
			// needs to be returned here so that browsers such as chrome that don't play nicely with scrollTop can still go to top of page.
			return false;
		});
		
	});
  
  
  /* ----------------------------
   * Set up slider for home page.
   * ----------------------------
   * Simon Winter 
   * 19 March 2010
   * ----
   * Activate the slider as used on the home page.
   * ---------------------------- */
   if($("#copyinner:has(#banner)")) {
		$("#banner").before('<div id="banner-menu">');
		$("#banner").cycle({ 
    		width: 977,
			height: 262,
			col: 4,
			duration: 2000,
			horiz: true,
			fade: true,
			effect: 'easeOutExpo',
    		pager:  '#banner-menu' 
		});
   };
   
   
   /* -------------------
   * Generate Mega Menu:
   * -------------------
   * Simon Winter
   * 01 March 2010
   * ----
   * Take sub menus from Joomla & convert to columns
   * by wrapping every n number of items in a div.
   * ------------------- */
   
   $("#menu ul").megaMenu({
		maxItems : 8, 
		borderColor : "#ffffff"
	});
   
  
  
 
	
	// utility function to enable us to grab a query string var.
	$.urlParam = function(name){
		var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
		if (!results)
			return 0;
		return results[1] || 0;
	}
	
	
	/*
	 * Assessment Form 
	 * Simon Winter
	 * 29 March 2010
	 * ----
	 * When we are passed to the asessment form, ensure that the info
	 * that is passed via the query string variables is inserted into the form.
	 */
	 if($("#copyinner:has(#assessmentForm)").length != 0) {
	 	var date = $.urlParam('date');
		var city = $.urlParam('city');
		var venue = $.urlParam('venue');
		
		/*if(document.referrer.indexOf("/free-lasik-assessments/")==-1) {
			document.location.href="/";
		}*/
		
	 	if(date != 0) {
	 		$("#date-requested").val(unescape(date));
		} else {
			$("#date-requested").val("dd/mm/yyyy");
		}
		
		$("#location option").each(function(i) {
			if($(this).val() == city) {
				$(this).attr("selected","selected");
			}
		});
		
		// replace the city with a hidden field.
		if(city != "") {
			$("#location").replaceWith("<input type=\"hidden\" id=\"location\" name=\"location\" value=\"" + city +"\" \>"+city);
		}
		
		// Only display the date selector for Christchurch dates.
		if(city.toLowerCase()!="christchurch") {
			printdate = date == "TBC" ? "To Be Confrimed" : date;
			$("#date-requested").replaceWith("<input type=\"hidden\" id=\"date-requested\" name=\"date-requested\" value=\"" + unescape(printdate) +"\" \>"+unescape(printdate));
		}
		
	 }
});
