/*

copyright Stephen Ensminger @ Media27, Inc.
2010 - 2011
*/
$(window).load(function() {
   
});

// onload standard function
$(document).ready(function()  
{  

	// set browser specific content
	if(jvars.browserType=="Firefox" || jvars.browserType=="Safari")
	{

	}

}); 


$(function(){

	$(window).resize(function() {	
		
	});	
	$(window).scroll(function() {
		
	});
		
});


$(function()
{

	var selectedCategoryButton = null;
	var selectedCategoryButtonId = null;
	var selectedId = 'DIVNAME';

	$("[class^='isMnupanel']").live('mouseenter', function (e) { 
		
		jQuery.hidePanels();
		
		var strclass = $(this).attr('class');
		
		// get name position
		var className = 'isMnupanel';
		var indexIn = strclass.indexOf(className);
		var indexSpace = strclass.indexOf(' ',indexIn);
		var indexQuote = strclass.indexOf('"',indexIn);
		var indexOut = (indexSpace<indexQuote || indexQuote==-1)?indexSpace :indexQuote;
		
		// extract number
		indexIn = indexIn + String(className).length; // 10
		var num = strclass.substring(indexIn,indexOut);
		
		// begin timer delay
		$('#panel'+num).show();
	}) 	
	.live('mouseleave', function (e) { 
			
		// put timer
		jvars.intervalId = setInterval('jQuery.hidePanels()', 1000);
	});
	
	
	$(".menupanel").live('mouseenter', function (e) { 
		
		// turn off timer delay
		if(jvars.intervalId)clearInterval(jvars.intervalId);
		
	}) 	
	.live('mouseleave', function (e) { 
			
		//				  
	  	$(this).hide();	
	});
	$(".menuitem").live('mouseenter', function (e) { 
		
		$(this).css('background-image','url(graphics/menuBkgRollOver_1px.png)');
		//$(this).next("span").removeClass('menulink').addClass('menulinkhover');
		
		jQuery(this).find("span").css('color','#000');
		
		//jQuery(this).nextAll("span").css('color','#000');
		//$(s).removeClass('menulink').addClass('menulinkhover');
		  
	}) 	
	.live('mouseleave', function (e) { 
			
		// put timer					  
	  	$(this).css('background-image','none');	
		
		jQuery(this).find("span").css('color','#FFF');
		
	});
	
	//////
	
	

	// IMG HANDOVER
	$('img.isButton').hover(function()
	{		  
		$(this).attr("src", $(this).attr("src").replace("_off.", "_over."));
		
	}, function() {
		
		  $(this).attr("src", $(this).attr("src").replace("_over.", "_off."));
	});

	
	// SAME AS ABOVE using mouse events
	$('img.useLiveHandCursor').live('mouseenter', function (e) { 
		
		$(this).attr("src", $(this).attr("src").replace("_off.", "_over."));	
	}) 
	
	.live('mouseleave', function (e) { 
								  
	  	$(this).attr("src", $(this).attr("src").replace("_over.", "_off."));	
	});
	
	// link rollover (used for color change for text)
	$('.useLinkedCursor').hover(function()
	{		  
		// use color if exists
		var hoverClr = $(this).attr("colorHoverStyle");
	
		if(hoverClr)
			$(this).css("color", hoverClr);
		else
			$(this).css("color", "#4D4B48"); //B3B3B3 - 4D4B48
		
	}, function() {

		var clr = $(this).attr("colorStyle");
	
		if(clr)
			$(this).css("color", clr);
		else
			$(this).css("color", "#7BB309"); // 7BB309
	});
	// SAME AS ABOVE using mouse events (used for color change for text)
	$('.useLiveLinkedCursor').live('mouseenter', function (e) { 
		
		$(this).css("color", "#4D4B48");	
	}) 
	
	.live('mouseleave', function (e) { 
								  
	  	$(this).css("color", "#7BB309");	
	});
	

	// CLICKS

	
	// ajax
	$('a.ajList').live('click',function(e) {
		
		// decide how to handle the request
		var request = $(this).attr("request");
		
		var content = $('#'+request).attr('innerHTML');
		
		$('#trans2Content').attr('innerHTML',content);
		
		/*
		switch (request)
		{
			case "acquisition":
				break;
			case "banking":
				break;
			case "construction":
				break;
			case "counsel":
				break;
			case "employment":
				break;
			case "entertainment":
				break;
			case "entities":
				break;
			case "tax_planning":
				break;
			case "financing":
				break;
			case "property":
				break;
			case "transaction":
				break;
			case "licensing":
				break;
			case "litigation":
				break;
			case "merger":
				break;
			case "real_estate":
				break;
			case "startups":
				break;
			case "tax":
				break;
			case "water":
				break;
		}
		*/
		
	});

	$('.isButtonLink').live('click', function(e) {
		var request = $(this).attr("request");
		switch (request)
		{
			case "newsletterHandler":
				$("#newsletterSignup").attr("innerHTML","Please Sign Up");
				$("#newsletterSignup").css("display","block");
				
			
			break;
			
		}
		
		
		
	});


	
	  
	$('.isButton').live('click', function(e) {

		var _id;
		var _url;
		var _anch;
		var _title;
		var encoded_url;
		
	
		// decide how to handle the request
		var request = $(this).attr("request");
		switch (request)
		{

			
				
			//
			case "facebook_share":
				_url = encodeURIComponent('http://www.buynakfauver.com');
				_title = encodeURIComponent('Share Buynak Fauver!');
				encoded_url = 'http://www.facebook.com/sharer.php?u='+ _url +'&t='+_title;
				window.open(encoded_url, 'facebookShare');
				
				break;
				
			//
			case "twitter_share":
				_url = encodeURIComponent('http://www.buynakfauver.com');
				_title = encodeURIComponent('Buynak Fauver is on the web');
				encoded_url = 'http://twitter.com/share?url='+_url+'&text='+_title;
				window.open(encoded_url, 'twitterShare');
				
				break;
				
			//
			case "share_bymail":
				var subject = encodeURIComponent('Call Buynak Fauver Today');
				var bodytext = encodeURIComponent("A friend wants to share a part of Buynak Fauver with you. \nhttp://www.buynakfauver.com \n\n-------------------------\nBuynak Fauver.");
				encoded_url = 'mailto:?subject='+subject+'&body='+bodytext;
				//window.open(encoded_url, 'emailShare');
				window.location = encoded_url;
				
				break;
		}

	});
	
	
		
});


////
$(function()  
{

	(function($) {
		/*
		These query functions assume the post relies on common
		field values.
		*/

		$.hidePanels = function() {
			// stop interval transition if necessary
			if(jvars.intervalId)clearInterval(jvars.intervalId);
				
			$("[id^='panel']").hide();
		};

		$.showElement = function (element) {
			$('#'+element).show();
		};
		$.hideElement = function (element) {
			$('#'+element).css('display','none');
		};

	
		$.genericRequest = function(params) {
			// request data
			if(jvars.postParams)
			{
				jQuery.ajaxPostConstructor(jvars.postParams);
				jQuery.ajaxRequest('./27php/request.php','genericStyleCallback',1);
			}
		};
		

		
	})(jQuery)
	
});

$(function()  
{

	(function($) {

		
		/*
		These query functions assume the post relies on common
		field values.
		*/
		$.validateInput = function(name,exception) {
			
			var element = $("#"+name);
			if(element.attr("value") != '')
			{
				if(exception && element.attr("value")==exception)
					return false;
				else
					return true;
			}
			
			return false;
		}
		$.validateChk = function(name) {
			
			var element = $("#"+name);

			if(element.is(':checked'))
				return true;		
			
			return false;
		}
		
		$.validateEmail = function(email)  {
			
			var em = (email)?email :jvars.userEmailAddress;

			// check email address
			if(em && em != "" && em !=0)  
			{  
				return jQuery.isValidEmailAddress(em); 
			} 


			return false;
		};
		$.validateEmailIfNotEmpty = function(email)  {
			
			var em = (email)?email :jvars.userEmailAddress;
			
			// check email address
			if(em && em != "" && em !=0)  
			{  
				return jQuery.isValidEmailAddress(em); 
			} 
			else if(!em || em == "") // if empty, just let it go
			{
				return true;	
			}


			return false;
		};
		$.validateRequiredFormFields = function(form) {
			
			var isValid = 1;
			
			$.each($('#'+form).serializeArray(), function(i, field) {
				if(field.value=='')
				{
					// because only name and value attributes are retained,
					// explicitly list elements to ignore
					if(field.name!='exception_input_field')
						isValid = 0;
				}
			}); 
	
			return isValid
		}
		$.isLengthValid = function(field,length) {
			
			var str = String();
			str = $("#"+field).val();
			
			if(str.length>=length)
				return true;
				
			return false
		}
		$.compileForms = function(arr_forms,excludedValue) {

			var values = {}; 
			
			$.each(arr_forms,function(k, element) {
				
				var name = $(element).attr('name');
				$.each($('#'+name).serializeArray(), function(j, field) {
	
					if(field.value!=excludedValue)
					{
						values[field.name] = field.value; 
					}
				});
							
			});
			
			return values;
		};

		$.compileFormFields = function(arr_forms,excludedValue) {

			var values = {}; 
			
			$.each(arr_forms, function(i, val) {
				$.each($('#'+val).serializeArray(), function(j, field) {
					if(field.value!=excludedValue)
						values[field.name] = field.value; 
				}); 
			
			});
			
			return values;
		};
		$.storeFieldValues = function(arr_forms,excludedValue,id) {

			var values = {}; 
			
			$.each(arr_forms, function(i, val) {
				$.each($('#'+val).serializeArray(), function(j, field) {
					if(field.value!=excludedValue)
					{
						//values[field.name] = field.value; 
						//alert(id+"|"+val+':'+field.name,field.value);
						jSetBrowserSession(id+"|"+val+':'+field.name,field.value); 
					}
				}); 
			
			});
			
			return values;
		};
		$.compare = function(compare1,compare2) {
			
			if(compare1 == compare2)
				return true;
				
			return false;
		};
		
		$.isValidEmailAddress = function(emailAddress) {  
		
			var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);  
		
			return pattern.test(emailAddress);  
		
		}; 
	
	})(jQuery)
	
});
