jQuery(document).ready(function(){
	
	jQuery('span.footer_image').hover(function() {
		jQuery('span.footer_text', this).stop().animate({height:'100%', duration: 1000, top: '0px'});
		}, 	
		function() {
    	 jQuery("span.footer_text", this).stop().animate({height:'100%', duration: 1000, top: '115px'});
	});



/*====== for the contact section of links in the header and mid_wrapper =======*/
	jQuery('div.email_wrapper, div.phone_wrapper, div.personal_wrapper, div.testimonial_wrapper').hide();
	
	jQuery("a.email_trigger").click(function()
	{
		phoneToggleUp();
		personalToggleUp();
		testimonialToggleUp();
		jQuery("div.email_wrapper").slideToggle("slow");
		return false;
	});
	
	jQuery("a.phone_trigger").click(function()
	{
		emailToggleUp();
		personalToggleUp();
		testimonialToggleUp();
		jQuery("div.phone_wrapper").slideToggle("slow");
		return false;
	});
	
	jQuery("a.personal_trigger").click(function()
	{
		emailToggleUp();
		phoneToggleUp();
		testimonialToggleUp();
		jQuery("div.personal_wrapper").slideToggle("slow");
		return false;
	});
	
	jQuery("a.testies_trigger").click(function()
	{
		emailToggleUp();
		phoneToggleUp();
		personalToggleUp();
		jQuery("div.testimonial_wrapper").slideToggle("slow");
		return false;
	});
	
/* functions to make the divs disapear */	
	function emailToggleUp(){
		jQuery("div.email_wrapper").slideUp("slow");
	}

	function personalToggleUp(){
		jQuery("div.personal_wrapper").slideUp("slow");
	}

	function phoneToggleUp(){
		jQuery("div.phone_wrapper").slideUp("slow");
	}
	
	function testimonialToggleUp(){
		jQuery("div.testimonial_wrapper").slideUp("slow");
	}
	
	//close all function
	function closeAll(){
		emailToggleUp();
		phoneToggleUp();
		personalToggleUp();
		testimonialToggleUp();			
	}
	
/* ===== ends here ===== */
	
	//listens to the escape key and if pressed removes the contact panel
	jQuery(document).keyup(function(event){
		if (event.keyCode == 27) {
		   	closeAll();
		}
	});
	
	//so i can close al the divs with a button
	jQuery('a.close_trigger').click(function(){
		closeAll();					
	});
	
	
/* for the whats next section request a call back */
	jQuery("div#whats_next ul li.callback ul#callback_content").hide();
	
	jQuery("a.callback_trigger").click(function()
	{
		jQuery("div#whats_next ul li.callback").toggleClass('active');
		jQuery("div#whats_next ul li.callback ul#callback_content").slideToggle("slow");
		return false;
	});


/*for the category list pages to show and hide their extra details */
	jQuery('div.itemmeta_content').hide();
	jQuery("a.itemmeta_trigger").click(function()
	{
		jQuery(this).next("div.itemmeta_content").slideToggle("slow");
		jQuery(this).toggleClass('active');
		return false;
	});
	
	
/* adds a little more advanced css selecting to the site. css3 stuff but universal */
	jQuery('li.recommended:last').addClass('thumbs');
	jQuery('li.connections:last').addClass('network');
	
	
/*for the text highlighting on the search page */
//http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
jQuery.fn.highlight = function(pat) {
function innerHighlight(node, pat) 
{
	var skip = 0;
	if (node.nodeType == 3) 
	{
		var pos = node.data.toUpperCase().indexOf(pat);
		if (pos >= 0) 
		{
			var spannode = document.createElement('span');
			spannode.className = 'highlight';
			var middlebit = node.splitText(pos);
			var endbit = middlebit.splitText(pat.length);
			var middleclone = middlebit.cloneNode(true);
			spannode.appendChild(middleclone);
			middlebit.parentNode.replaceChild(spannode, middlebit);
			skip = 1;
		}
	}
	else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) 
	{
		for (var i = 0; i < node.childNodes.length; ++i) 
		{
			i += innerHighlight(node.childNodes[i], pat);
		}
	}
	return skip;
}

return this.each(function() 
{
	innerHighlight(this, pat.toUpperCase());
});
};

jQuery.fn.removeHighlight = function() 
{
return this.find("span.highlight").each(function() 
{
this.parentNode.firstChild.nodeName;
with (this.parentNode) 
{
	replaceChild(this.firstChild, this);
	normalize();
}
}).end();
};


	
var $ = jQuery.noConflict();	
//Setup Arrays that will hold the x,y,z of each element.
var x = new Array();
var y = new Array();
var z = new Array();

//Get the list of items.
var items = $('#header_top_front ul li');

//Animate the items.
function animate()
{
   
    //Step through each item.
    for(i = items.length - 1; i >= 0; i--){
       
       
        //variables for movement.          
        var xVar = 5 + x[i]            // x value
        var yVar = 50 + y[i] * z[i]++;  // y value, move towards bottom of screen
        var zVar = 5 * z[i]++;         // z value, text get larger.
       
       
        //Check to see if text position is still on the screen.
        // the #'s are %.   100 is far right or bottom, 0 is top or left.
        // for z value it's the font size in %.
        if (!xVar | xVar < 0 | xVar > 90|
            yVar < 0 | yVar > 90 |
            zVar < 0 | zVar > 1500)
        {
            //if it's off the screen randomly pick a starting place.
            x[i] = Math.random() * 2 - 1;
            y[i] = Math.random() * 2 - 1;
            z[i] = 2;
           
        }
        else
        {
            //if it's still on the screen apply the appropiate styles.
           
            $(items[i]).css("position", "absolute"); // make sure we can move the text around.
            $(items[i]).css("top", xVar+"%");  // y value
            $(items[i]).css("left", yVar+"%"); // x value
           
            $(items[i]).css("fontSize", zVar+"%"); // font size (illusion of perspective.)
            $(items[i]).css("opacity",(zVar)/3000); // fade in from the distance.
        }
    }

    setTimeout(animate, 2);
}

animate();

//turn off the flying stuff
$('a.clear_flying').click(function(){
	$('ul#flying').remove();	
	$.cookie('flying_off', '1');	
});


/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
	
});
