/* Author: 
Daniel Łęczycki www.designsentry.com
*/

jQuery(document).ready(function() {

	/* Search on hover effect, focus effect, and double-click to erase value */
	hasFocci = false;
	jQuery('#search_input').focus(function(){
		jQuery(this).stop().animate({"opacity": "1"},{queue:false,duration:300});
		hasFocci = true;
	}).blur(function() {
		jQuery(this).stop().animate({"opacity": "0.01"},{queue:false,duration:300});
		hasFocci = false;
	}).dblclick(function() {
		jQuery(this).val('');
		hasFocci = true;
	});
	jQuery('#search_submit').add('#search_input').hover(function(){
		jQuery(this).stop().animate({"opacity": "1"},{queue:false,duration:300});
	},function() {
		if(!hasFocci){jQuery(this).stop().animate({"opacity": "0.01"},{queue:false,duration:300});}
	});
	
	jQuery('#menu > ul > li').prepend('<span class="menu_box_left"></span>').append('<span class="menu_box_right"></span>');
	/* Menu jQuery rollout, additional styling allowing for rounded borders */
	var Menus = jQuery('#menu ul li');
	if(!(jQuery.browser.msie && jQuery.browser.version.substr(0,1)<8)){Menus.find('ul li').has('ul li').find('>a').append('<span> &raquo;</span>');}
	Menus.find('ul li:first-child').addClass('first_sub png_bg');
	Menus.find('ul').append('<li class="last_sub png_bg"></li>');
	Menus.find('ul').css({display: "none"}); // Opera Fix
	Menus.hover(function(){
		jQuery(this).not(':has(ul)').find('> a').addClass('menu_box_mid_bg');
		jQuery(this).has('ul').find('> a').addClass('menu_box_mid_bg_has_li');
		jQuery('span.menu_box_left', this).addClass('menu_box_left_bg');
		jQuery('span.menu_box_right', this).addClass('menu_box_right_bg');
	},function() {
		jQuery(this).not(':has(ul)').find('> a').removeClass('menu_box_mid_bg');
		jQuery(this).has('ul').find('> a').removeClass('menu_box_mid_bg_has_li');
		jQuery('span.menu_box_left', this).removeClass('menu_box_left_bg');
		jQuery('span.menu_box_right', this).removeClass('menu_box_right_bg');
	});
	Menus.hoverIntent({
	over: makeTall, 
	timeout: 300, 
	out: makeShort
	});
	function makeTall(){ jQuery(this).find('ul:first').slideDown({queue:false,duration:220});}
	function makeShort(){ jQuery(this).find('ul:first').fadeOut({queue:true,duration:200});}
	
	
	
	/* Inner HR autofill */
	jQuery('.inner_main .hr').append('<div class="inner_hr"></div>');
	
	/* Pricing Table */
	var pricingcolumn = jQuery('.pricing_column');
	pricingcolumn.hover(function(){
		jQuery(this).find('.pricing_blurb').animate({top: '10px'},300);
	},function(){
		jQuery(this).find('.pricing_blurb').animate({top: '0px'},300);
	});
	
	/* Set the pricing tables to the right size */
	var pricingrowselector = jQuery('.pricing');
	pricingrowselector.each(function(){
		var numberofcolumns = jQuery(this).find('.pricing_column').length;
		var widthofrow = jQuery(this).parent().width();
		var finalresult = (11 + Math.floor(((widthofrow-2) - (numberofcolumns * (168)))/(numberofcolumns * 2)));
		jQuery(this).find('.pricing_blurb').css({marginLeft: finalresult,marginRight: finalresult});
	});
	
	
	

	
	
});
/* End of onstart functions */

/* Start of functions initialized after full load of page */
jQuery(window).load(function(){
	

	
	/* Adding some Border magic */
	var borderSubject = jQuery('.inner_main .border_magic, #footer .border_magic');
	borderSubject.wrap('<div class="add_border" />');
	
	/* Transfering alignment to added border */
	var bordered = jQuery('.inner_main .add_border, #footer .add_border');
	bordered.find('.alignleft').removeClass('alignleft').parent().addClass('alignleft');
	bordered.find('.alignright').removeClass('alignright').parent().addClass('alignright');
	bordered.find('.no_bottom_margin').removeClass('no_bottom_margin').parent().addClass('no_bottom_margin');
	
	
	/* Making the added border width completely automatic */
	borderSubject.each(function(){
	var addBordi = jQuery(this).width();
	jQuery(this).parent().width(addBordi+10);
	});
	
	/* Smooth image load */
	borderSubject.fadeIn(1500).parent().delay(1500).queue(function() {jQuery(this).css('background-image','url(css/img/zoom.png)');});
	
	/* Catch the height of longest footer column and stretch the others to the same size */
	var highHeels = 0;
	jQuery('#footer .widget').each(function(){
	var topHeels = jQuery(this).height();
	if(topHeels > highHeels){highHeels = topHeels};
	});
	jQuery('#footer .widget').height(highHeels);
	

	
});

