/* ===========================================================================
 *
 * JQuery URL Parser
 * Version 1.0
 * Parses URLs and provides easy access to information within them.
 *
 * Author: Mark Perkins
 * Author email: mark@allmarkedup.com
 *
 * For full documentation and more go to http://projects.allmarkedup.com/jquery_url_parser/
 *
 * ---------------------------------------------------------------------------
 *
 * CREDITS:
 *
 * Parser based on the Regex-based URI parser by Steven Levithan.
 * For more information (including a detailed explaination of the differences
 * between the 'loose' and 'strict' pasing modes) visit http://blog.stevenlevithan.com/archives/parseuri
 *
 * ---------------------------------------------------------------------------
 *
 * LICENCE:
 *
 * Released under a MIT Licence. See licence.txt that should have been supplied with this file,
 * or visit http://projects.allmarkedup.com/jquery_url_parser/licence.txt
 *
 * ---------------------------------------------------------------------------
 * 
 * EXAMPLES OF USE:
 *
 * Get the domain name (host) from the current page URL
 * jQuery.url.attr("host")
 *
 * Get the query string value for 'item' for the current page
 * jQuery.url.param("item") // null if it doesn't exist
 *
 * Get the second segment of the URI of the current page
 * jQuery.url.segment(2) // null if it doesn't exist
 *
 * Get the protocol of a manually passed in URL
 * jQuery.url.setUrl("http://allmarkedup.com/").attr("protocol") // returns 'http'
 *
 */

jQuery.url = function()
{
	var segments = {};
	
	var parsed = {};
	
	/**
    * Options object. Only the URI and strictMode values can be changed via the setters below.
    */
  	var options = {
	
		url : window.location, // default URI is the page in which the script is running
		
		strictMode: false, // 'loose' parsing by default
	
		key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], // keys available to query 
		
		q: {
			name: "queryKey",
			parser: /(?:^|&)([^&=]*)=?([^&]*)/g
		},
		
		parser: {
			strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,  //less intuitive, more accurate to the specs
			loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs
		}
		
	};
	
    /**
     * Deals with the parsing of the URI according to the regex above.
 	 * Written by Steven Levithan - see credits at top.
     */		
	var parseUri = function()
	{
		str = decodeURI( options.url );
		
		var m = options.parser[ options.strictMode ? "strict" : "loose" ].exec( str );
		var uri = {};
		var i = 14;

		while ( i-- ) {
			uri[ options.key[i] ] = m[i] || "";
		}

		uri[ options.q.name ] = {};
		uri[ options.key[12] ].replace( options.q.parser, function ( $0, $1, $2 ) {
			if ($1) {
				uri[options.q.name][$1] = $2;
			}
		});

		return uri;
	};

    /**
     * Returns the value of the passed in key from the parsed URI.
  	 * 
	 * @param string key The key whose value is required
     */		
	var key = function( key )
	{
		if ( ! parsed.length )
		{
			setUp(); // if the URI has not been parsed yet then do this first...	
		} 
		if ( key == "base" )
		{
			if ( parsed.port !== null && parsed.port !== "" )
			{
				return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/";	
			}
			else
			{
				return parsed.protocol+"://"+parsed.host+"/";
			}
		}
	
		return ( parsed[key] === "" ) ? null : parsed[key];
	};
	
	/**
     * Returns the value of the required query string parameter.
  	 * 
	 * @param string item The parameter whose value is required
     */		
	var param = function( item )
	{
		if ( ! parsed.length )
		{
			setUp(); // if the URI has not been parsed yet then do this first...	
		}
		return ( parsed.queryKey[item] === null ) ? null : parsed.queryKey[item];
	};

    /**
     * 'Constructor' (not really!) function.
     *  Called whenever the URI changes to kick off re-parsing of the URI and splitting it up into segments. 
     */	
	var setUp = function()
	{
		parsed = parseUri();
		
		getSegments();	
	};
	
    /**
     * Splits up the body of the URI into segments (i.e. sections delimited by '/')
     */
	var getSegments = function()
	{
		var p = parsed.path;
		segments = []; // clear out segments array
		segments = parsed.path.length == 1 ? {} : ( p.charAt( p.length - 1 ) == "/" ? p.substring( 1, p.length - 1 ) : path = p.substring( 1 ) ).split("/");
	};
	
	return {
		
	    /**
	     * Sets the parsing mode - either strict or loose. Set to loose by default.
	     *
	     * @param string mode The mode to set the parser to. Anything apart from a value of 'strict' will set it to loose!
	     */
		setMode : function( mode )
		{
			strictMode = mode == "strict" ? true : false;
			return this;
		},
		
		/**
	     * Sets URI to parse if you don't want to to parse the current page's URI.
		 * Calling the function with no value for newUri resets it to the current page's URI.
	     *
	     * @param string newUri The URI to parse.
	     */		
		setUrl : function( newUri )
		{
			options.url = newUri === undefined ? window.location : newUri;
			setUp();
			return this;
		},		
		
		/**
	     * Returns the value of the specified URI segment. Segments are numbered from 1 to the number of segments.
		 * For example the URI http://test.com/about/company/ segment(1) would return 'about'.
		 *
		 * If no integer is passed into the function it returns the number of segments in the URI.
	     *
	     * @param int pos The position of the segment to return. Can be empty.
	     */	
		segment : function( pos )
		{
			if ( ! parsed.length )
			{
				setUp(); // if the URI has not been parsed yet then do this first...	
			} 
			if ( pos === undefined )
			{
				return segments.length;
			}
			return ( segments[pos] === "" || segments[pos] === undefined ) ? null : segments[pos];
		},
		
		attr : key, // provides public access to private 'key' function - see above
		
		param : param // provides public access to private 'param' function - see above
		
	};
	
}();
// jQuery URL parser END -- Start custom jQuery
	$(document).ready(function() {
		// jQuery used for mouseovers on all pages
		$('#us_button_over').hide();
		$('img.mo').hide();
		
		$('div#call_to_action').mouseover(function() {
			$('div.call_to_action_button').hide();
			$('div#call_mo').removeClass('call_to_action_button_over');
		});
		$('div#call_to_action').mouseout(function() {
			$('div.call_to_action_button').show();
			$('div#call_mo').addClass('call_to_action_button_over');
		});
		$('#us_button').mouseover(function() {
			$('#us_button_out').hide();
			$('#us_button_over').show();
		});
		$('#us_button').mouseout(function() {
			$('#us_button_out').show();
			$('#us_button_over').hide();
		});
		
		/*  The following block of code is to set the state
			of the nav buttons based on the current page
		*/
		
		// Create variables for the page URLs
		var aboutURL = "about-best-pizza-franchise.php";
		var buzzURL = "why-fast-food-franchises.php";
		var whyusURL = "pizza-hut-testimonials.php";
		var trainingURL = "pizza-franchise-for-sale-process.php";
		var testimonialsURL = "growth-markets-top-pizza-franchise.php";
		var processURL = "the-investment-pizza-franchise-opportunities.php";
		var growthURL = "pizza-hut-frequently-asked-questions.php";
		
		// Retrieve the current relative URL (set the segment to 0 when moving pages out of the "new" folder)
		var currpath = jQuery.url.segment(0); // null if it doesn't exist
		
		if(currpath == aboutURL) {
			$('#nav_about').removeClass('sidenav_mo');
			$('#nav_about').find('img.reg').hide();
			$('#nav_about').find('img.mo').show();
		} else if(currpath == buzzURL) {
			$('#nav_buzz').removeClass('sidenav_mo');
			$('#nav_buzz').find('img.reg').hide();
			$('#nav_buzz').find('img.mo').show();
		} else if(currpath == whyusURL) {
			$('#nav_why_us').removeClass('sidenav_mo');
			$('#nav_why_us').find('img.reg').hide();
			$('#nav_why_us').find('img.mo').show();
		} else if(currpath == trainingURL) {
			$('#nav_training').removeClass('sidenav_mo');
			$('#nav_training').find('img.reg').hide();
			$('#nav_training').find('img.mo').show();
		} else if(currpath == testimonialsURL) {
			$('#nav_testimonials').removeClass('sidenav_mo');
			$('#nav_testimonials').find('img.reg').hide();
			$('#nav_testimonials').find('img.mo').show();
		} else if(currpath == processURL) {
			$('#nav_process').removeClass('sidenav_mo');
			$('#nav_process').find('img.reg').hide();
			$('#nav_process').find('img.mo').show();
		} else if(currpath == growthURL) {
			$('#nav_growth_markets').removeClass('sidenav_mo');
			$('#nav_growth_markets').find('img.reg').hide();
			$('#nav_growth_markets').find('img.mo').show();
		}/* else if(currpath == investURL) {
			$('#nav_investment').removeClass('sidenav_mo');
			$('#nav_investment').find('img.reg').hide();
			$('#nav_investment').find('img.mo').show();
		} else if(currpath == faqURL) {
			$('#nav_faq').removeClass('sidenav_mo');
			$('#nav_faq').find('img.reg').hide();
			$('#nav_faq').find('img.mo').show();
		} else if(currpath == requestURL) {
			$('#nav_request').removeClass('sidenav_mo');
			$('#nav_request').find('img.reg').hide();
			$('#nav_request').find('img.mo').show();
		}*/
		// Side Navigation mouse-over functions
		$('div.sidenav_mo').mouseover(function() {
			$(this).find('img.reg').hide();
			$(this).find('img.mo').show();
		});
		$('div.sidenav_mo').mouseout(function() {
			$(this).find('img.reg').show();
			$(this).find('img.mo').hide();
		});
		
		// Home page specific jQuery
		$('#home_button_1').mouseover(function() {
			$(this).toggleClass('button_1_out, button_1_over');
		});
		$('#home_button_1').mouseout(function() {
			$(this).toggleClass('button_1_out, button_1_over');
		});
		$('#home_button_3').mouseover(function() {
			$(this).toggleClass('button_3_out, button_3_over');
		});
		$('#home_button_3').mouseout(function() {
			$(this).toggleClass('button_3_out, button_3_over');
		});
		
		// Our Process page specific jQuery
		
		$('#interviews, #approval, #area_selection, #area_approval, #con_train_open, #growth, #additional, #line_2, #line_3, #line_4, #line_5, #line_6, #line_7, #line_8').hide();
		$('div.selected').find('img.reg').hide();
		$('div.selected').find('img.mo').show();
		
		$('div.deselect').mouseover(function() {
			$(this).find('img.reg').hide();
			$(this).find('img.mo').show();
		});
		$('div.deselect').mouseout(function() {
			$(this).find('img.mo').hide();
			$(this).find('img.reg').show();
		});
		$('div#op_btn_1, #op_lines_1').click(function() {
			$(this).removeClass('deselect').addClass('selected');
			$('#op_btn_2, #op_btn_3, #op_btn_4, #op_btn_5, #op_btn_6, #op_btn_7, #op_btn_8').removeClass('selected').addClass('deselect');
			$('.deselect').find('img.mo').hide();
			$('.deselect').find('img.reg').show();
			$('.selected').find('img.reg').hide();
			$('.selected').find('img.mo').show();
			$('div.deselect').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.deselect').mouseout(function() {
				$(this).find('img.mo').hide();
				$(this).find('img.reg').show();
			});
			$('div.selected').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.selected').mouseout(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			
			$('#interviews, #approval, #area_selection, #area_approval, #con_train_open, #growth, #additional, #line_2, #line_3, #line_4, #line_5, #line_6, #line_7, #line_8').hide();
			$('div#qualifications, #line_1').show();
		});
		$('div#op_btn_2, #op_lines_5').click(function() {
			$(this).removeClass('deselect').addClass('selected');
			$('#op_btn_1, #op_btn_3, #op_btn_4, #op_btn_5, #op_btn_6, #op_btn_7, #op_btn_8').removeClass('selected').addClass('deselect');
			$('.deselect').find('img.mo').hide();
			$('.deselect').find('img.reg').show();
			$('.selected').find('img.reg').hide();
			$('.selected').find('img.mo').show();
			$('div.deselect').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.deselect').mouseout(function() {
				$(this).find('img.mo').hide();
				$(this).find('img.reg').show();
			});
			$('div.selected').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.selected').mouseout(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});

			$('#interviews, #approval, #area_selection, #qualifications, #con_train_open, #growth, #additional, #line_2, #line_3, #line_4, #line_1, #line_6, #line_7, #line_8').hide();
			$('div#area_approval, #line_5').show();
		});
		$('div#op_btn_3, #op_lines_2').click(function() {
			$(this).removeClass('deselect').addClass('selected');
			$('#op_btn_1, #op_btn_2, #op_btn_4, #op_btn_5, #op_btn_6, #op_btn_7, #op_btn_8').removeClass('selected').addClass('deselect');
			$('.deselect').find('img.mo').hide();
			$('.deselect').find('img.reg').show();
			$('.selected').find('img.reg').hide();
			$('.selected').find('img.mo').show();
			$('div.deselect').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.deselect').mouseout(function() {
				$(this).find('img.mo').hide();
				$(this).find('img.reg').show();
			});
			$('div.selected').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.selected').mouseout(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});

			$('#area_approval, #approval, #area_selection, #qualifications, #con_train_open, #growth, #additional, #line_1, #line_3, #line_4, #line_5, #line_6, #line_7, #line_8').hide();
			$('div#interviews, #line_2').show();
		});
		$('div#op_btn_4, #op_lines_6').click(function() {
			$(this).removeClass('deselect').addClass('selected');
			$('#op_btn_1, #op_btn_2, #op_btn_3, #op_btn_5, #op_btn_6, #op_btn_7, #op_btn_8').removeClass('selected').addClass('deselect');
			$('.deselect').find('img.mo').hide();
			$('.deselect').find('img.reg').show();
			$('.selected').find('img.reg').hide();
			$('.selected').find('img.mo').show();
			$('div.deselect').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.deselect').mouseout(function() {
				$(this).find('img.mo').hide();
				$(this).find('img.reg').show();
			});
			$('div.selected').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.selected').mouseout(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});

			$('#area_approval, #approval, #area_selection, #qualifications, #interviews, #growth, #additional, #line_2, #line_3, #line_4, #line_5, #line_1, #line_7, #line_8').hide();
			$('div#con_train_open, #line_6').show();
		});
		$('div#op_btn_5, #op_lines_3').click(function() {
			$(this).removeClass('deselect').addClass('selected');
			$('#op_btn_1, #op_btn_2, #op_btn_3, #op_btn_4, #op_btn_6, #op_btn_7, #op_btn_8').removeClass('selected').addClass('deselect');
			$('.deselect').find('img.mo').hide();
			$('.deselect').find('img.reg').show();
			$('.selected').find('img.reg').hide();
			$('.selected').find('img.mo').show();
			$('div.deselect').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.deselect').mouseout(function() {
				$(this).find('img.mo').hide();
				$(this).find('img.reg').show();
			});
			$('div.selected').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.selected').mouseout(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});

			$('#area_approval, #con_train_open, #area_selection, #qualifications, #interviews, #growth, #additional, #line_2, #line_1, #line_4, #line_5, #line_6, #line_7, #line_8').hide();
			$('div#approval, #line_3').show();
		});
		$('div#op_btn_6, #op_lines_7').click(function() {
			$(this).removeClass('deselect').addClass('selected');
			$('#op_btn_1, #op_btn_2, #op_btn_3, #op_btn_4, #op_btn_5, #op_btn_7, #op_btn_8').removeClass('selected').addClass('deselect');
			$('.deselect').find('img.mo').hide();
			$('.deselect').find('img.reg').show();
			$('.selected').find('img.reg').hide();
			$('.selected').find('img.mo').show();
			$('div.deselect').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.deselect').mouseout(function() {
				$(this).find('img.mo').hide();
				$(this).find('img.reg').show();
			});
			$('div.selected').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.selected').mouseout(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});

			$('#area_approval, #con_train_open, #area_selection, #qualifications, #interviews, #approval, #additional, #line_2, #line_3, #line_4, #line_5, #line_6, #line_1, #line_8').hide();
			$('div#growth, #line_7').show();
		});
		$('div#op_btn_7, #op_lines_4').click(function() {
			$(this).removeClass('deselect').addClass('selected');
			$('#op_btn_1, #op_btn_2, #op_btn_3, #op_btn_4, #op_btn_5, #op_btn_6, #op_btn_8').removeClass('selected').addClass('deselect');
			$('.deselect').find('img.mo').hide();
			$('.deselect').find('img.reg').show();
			$('.selected').find('img.reg').hide();
			$('.selected').find('img.mo').show();
			$('div.deselect').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.deselect').mouseout(function() {
				$(this).find('img.mo').hide();
				$(this).find('img.reg').show();
			});
			$('div.selected').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.selected').mouseout(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});

			$('#area_approval, #con_train_open, #growth, #qualifications, #interviews, #approval, #additional, #line_2, #line_3, #line_1, #line_5, #line_6, #line_7, #line_8').hide();
			$('div#area_selection, #line_4').show();
		});
		$('div#op_btn_8, #op_lines_8').click(function() {
			$(this).removeClass('deselect').addClass('selected');
			$('#op_btn_1, #op_btn_2, #op_btn_3, #op_btn_4, #op_btn_5, #op_btn_6, #op_btn_7').removeClass('selected').addClass('deselect');
			$('.deselect').find('img.mo').hide();
			$('.deselect').find('img.reg').show();
			$('.selected').find('img.reg').hide();
			$('.selected').find('img.mo').show();
			$('div.deselect').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.deselect').mouseout(function() {
				$(this).find('img.mo').hide();
				$(this).find('img.reg').show();
			});
			$('div.selected').mouseover(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});
			$('div.selected').mouseout(function() {
				$(this).find('img.reg').hide();
				$(this).find('img.mo').show();
			});

			$('#area_approval, #con_train_open, #growth, #qualifications, #interviews, #approval, #area_selection, #line_2, #line_3, #line_1, #line_5, #line_6, #line_7, #line_4').hide();
			$('div#additional, #line_8').show();
		});
	});
