/*------------------------------------------------------------------------------

	thunder.client
	
	(c) 2010 thunder::tech
	http://www.thundertech.com/

	Each method is documented using the following terms.
	
	hook: JQuery/CSS hook that activates the functionality on an element
	output: The change that the functionality results in; almost always in the form of a JQuery/CSS hook change

	Filename             thunder.js
	Detail               Standard process library
	Author:              thunder::tech inc.
	License:             CLIENT is defined as the owner of online property from which this file resides or this code is referenced in.
						 ADDITIONAL party is defined as anyone other than thunder::tech or CLIENT.
						 No right is granted to CLIENT or ADDITIONAL PARTY to sell, distribute, modify or otherwise transfer the following source code without explicit written permission by thunder::tech.

------------------------------------------------------------------------------*/

var thunder = { client: { project: { utils: {} }, modify: {}, workarounds: {} } };

/*------------------------------------------------------------------------------

	thunder.client.modify
	Create dynamic interactivity by modifying existing markup

------------------------------------------------------------------------------*/

	// method thunder.client.modify.selfLabelFields()
	// hook: .thunder-self-labeled
	// uses existing value attribute as label
	// sets thunder.markup:label attribute
	// output: toggling .thunder-label-cleared
	thunder.client.modify.selfLabelFields = function()
	{
		// Auto-label search field
		$(".thunder-self-labeled").each(function(i)
		{
			this.setAttribute('thunder.markup:label',this.value)
		}).focus(function()
		{
			if(this.value==this.getAttribute('thunder.markup:label'))
			{
				this.value='';
				$(this).addClass('thunder-label-cleared');
			}
		}).blur(function()
		{
			if(this.value=='')
			{
				this.value=this.getAttribute('thunder.markup:label');
				$(this).removeClass('thunder-label-cleared');
			}
		});	
	};

	// method thunder.client.modify.Menu()
	// parameter wl:Boolean ? hide window layer objects when menu is active?
	// hook: .thunder-menu
	// output: toggling .thunder-nav-on
	thunder.client.modify.Menu = function(wl)
	{
		$('.thunder-menu > li').mouseenter(function()
		{
			$(this).addClass('thunder-nav-on');
		}).mouseleave(function()
		{
			$(this).removeClass('thunder-nav-on');
		});
		if(wl)
		{
			$('.thunder-menu').mouseenter(function()
			{
				thunder.client.workarounds.windowLayer(false);
			}).mouseleave(function()
			{
				thunder.client.workarounds.windowLayer(true);
			});
		}
		
		$('.dropdown > li:first-child').css("padding-top", "5px");
	};

	// method thunder.client.workarounds.windowLayer
	// b:Booolean ? show window layer objects : hide them
	thunder.client.workarounds.windowLayer = function(b)
	{
		if(b==true)
		{
			$(document).find('select').css('visibility', 'visible');
		}
		else
		{
			$(document).find('select').css('visibility', 'hidden');
		}
	}

	// method thunder.client.modify.tabSet()
	// hooks: .thunder-tab, .thunder-tab-window
	// correlator: (tab) thunder.markup:item="css-hook" e.g. #this-tab-window or .these-tab-windows
	// output: toggling .thunder-tab-on, .thunder-tab-window-on
	// parameters: c:Function; callback(s) where s:String is thunder.markup:item
	thunder.client.modify.tabSet = function(c)
	{
		$('.thunder-tab').click(function()
		{
			$('.thunder-tab').removeClass('thunder-tab-on');
			$('.thunder-tab-window').removeClass('thunder-tab-window-on');
			$(this).addClass('thunder-tab-on');
			$(this.getAttribute('thunder.markup:item')).addClass('thunder-tab-window-on');
			if(c) c(this.getAttribute('thunder.markup:item'));
		});
	}
	
	// method thunder.client.modify.linkOptions()
	// hook: .thunder-link-options
	// output: changes window.location to value attribute
	thunder.client.modify.linkOptions = function()
	{
		$('.thunder-link-options').change(function()
		{
			var u, i;
			for(i=0;i<this.options.length;i++)
			{
				if(this.options[i].selected==true) window.location = this.options[i].value;
			}
		});
	}
	
