/*****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	This function sets the default functionality
 *	for search boxes and ratings input then makes 
 *	a call to InitTabs()
 *
 *	Function Paramaters
 *	-------------------
 *	None
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *	- InitTabs()
 *
 *****************************************************/
$(function() {
	if($("#site-search-box").val() == "")
		$("#site-search-box").val("Search Site");
	$("#site-search-box").focus(function() {
		if($(this).val() == $(this).attr("title"))	
		{
			$(this).val("");
			$(this).removeClass("text-color-light");
		}
	});//END 'focus' Event

	$("#site-search-box").blur(function() {
		if($(this).val() == "")
		{
			$(this).val($(this).attr("title"));
			$(this).addClass("text-color-light");
		}
	});//END 'blur' Event

	$(".search-box").focus(function() {
		if($(this).val() == $(this).attr("title"))
		{
			$(this).val("");
			$(this).addClass("search-box-focus");
			$(this).removeClass("text-color-light");
		}
	});//END 'focus' Event

	$(".search-box").blur(function() {
		if($(this).val() == "")
		{
			$(this).val($(this).attr("title"));
			$(this).removeClass("search-box-focus");
			$(this).addClass("text-color-light");
		}
	});//END 'blur' Event

	$(".write-review-apply-rating input").click(function() {
		var T = $(this).attr("id");
		var Number = parseInt(T.substring(T.length - 1, T.length)) + 1;

		$("#"+ $(this).attr("rel")).val(parseInt(Number) - 1);
		
		$(".write-review-apply-rating input").attr("checked","");
		for(var i = 0; i < Number; i++)
		{
			$("#write-review-apply-rating-"+ i).attr("checked","checked");
		}//END 'for' loop
	});//END 'click' Event
	InitTabs();
});

/*****************************************************
 *	Function: InitTabs()
 *****************************************************
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	This function sets the defaults for tab styling
 *	when selecting a tab
 *
 *	Function Paramaters
 *	-------------------
 *	None
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function InitTabs()
{
	$(".tab-button").click(function() {
		$(this).parent().find(".tab-button").removeClass("select");
		$(this).parent().find(".tab-button").removeClass("background");
		$(this).parent().find(".tab-button").addClass("background-light");

		$(this).removeClass("background-light");
		$(this).addClass("select");
		$(this).addClass("background");

		$(this).parent().parent().find(".tab-content").hide();
		$("#"+ $(this).attr("rel")).show();
	});//END 'click' Event

	$(".tab-buttons-wrapper .select").click();
}//End InitTabs function

/*****************************************************
 *	Function: WindowLoad(Url, JavaFunction)
 *****************************************************
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	This function loads a popup dialog box in the
 *	center of the screen with data from the given
 *	Url.
 *
 *	Function Paramaters
 *	-------------------
 *	Url - The location of the data to be loaded
 *	JavaFunction - No logic exists for this parameter 
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function WindowLoad(Url, JavaFunction)
{
	//Sets the window to a loading state
	$("#window-popup-wrapper").addClass("window-popup-loading");
	$("#window-popup").html("");

	//Put in place to prevent caching with the Url
	var randonNumber = Math.random() +'';
	Url += '&RND='+ randonNumber.replace('0.','');

	//Setting dimensions for the popup
	var winH = parseInt($(window).height());
	var winW = parseInt($(window).width());

	$("#window-popup-wrapper").width(300);
	$("#window-popup-wrapper").height(200);

	var left = (winW / 2) - 150;
	var top = (winH / 2) - 100;


	$("#window-popup-wrapper").css("top", top +"px");
	$("#window-popup-wrapper").css("left", left +"px");

	//Showing and populating the popup window with data
	$("#window-popup-wrapper").fadeIn(500, function(){
		$("#window-popup").load(Url, function(){
			$("#window-popup-wrapper").css("width","auto");
			$("#window-popup-wrapper").css("height","auto");

			var winH = parseInt($(window).height());
			var winW = parseInt($(window).width());

			var top = (winH / 2) - parseInt($("#window-popup-wrapper").outerHeight()) / 2;
			var left = (winW / 2) - parseInt($("#window-popup-wrapper").outerWidth()) / 2;

			$("#window-popup-wrapper").css("top", top +"px");
			$("#window-popup-wrapper").css("left", left +"px");

			$("#window-popup-wrapper").removeClass("window-popup-loading");
		});//END 'load' Event
	});//END 'fadeIn' Event
}//END 'WindowLoad' function

/*****************************************************
 *	Function: iframeWindow(Url, Height, Width)
 *****************************************************
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	This function loads a popup dialog box in an 
 *	iframe with data from the given Url.
 *
 *	Function Paramaters
 *	-------------------
 *	Url - The location of the data to be loaded
 *	Height - A value for the height of the box 
 *	Width - A value for the width of the box
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function iframeWindow(Url, Height, Width)
{
	$("#window-popup").html("");

	//sets the dimensions for the popup iframe
	var winH = parseInt($(window).height());
	var winW = parseInt($(window).width());

	$("#window-popup-wrapper").width(Width);
	$("#window-popup-wrapper").height(Height);

	var left = (winW / 2) - (Width / 2);
	var top = (winH / 2) - (Height / 2);


	$("#window-popup-wrapper").css("top", top +"px");
	$("#window-popup-wrapper").css("left", left +"px");

	//populates the data into the popup iframe
	$("#window-popup-wrapper").fadeIn(500, function()
	{
		$("#window-popup").html('<iframe src="'+ Url + UrlNoCache() +'" scrolling="no" frameborder="no" style="height: '+ Height +'px; width: '+ Width +'px;"></iframe>');		
	});//END 'fadeIn' Event
}//END 'iframWindow' function

/*****************************************************
 *	Function: WindowClose()
 *****************************************************
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	Closes the popup dialog box that was previously
 *	populated.
 *
 *	Function Paramaters
 *	-------------------
 *	None 
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function WindowClose()
{
	$("#window-popup-wrapper").fadeOut(500, function(){
		$("#window-popup").html("");
		$("#window-popup-wrapper").addClass("window-popup-loading");
	});//END 'fadeOut' Event
}//END 'WindowClose' function

/*****************************************************
 *	Function: WriteAReviewStarRating(Number)
 *****************************************************
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	Function appears to be redundant
 *
 *	Function Paramaters
 *	-------------------
 *	Number - the given rating from the user 
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function WriteAReviewStarRating(Number)
{
	$(".write-review-apply-rating input").attr("checked","");
	for(var i = 0; i < Number; i++)
	{
		$("#write-review-apply-rating-"+ Number).attr("checked","checked");
	}//END 'for' loop
}//END WriteAReviewStarRating function
