/**
 * Original Script by James Padosley for Nettuts.com
 * Updated to be based on his script as of Nov 18, 2009
 *
 * Modified by Patrick Eisenmann to support history and lightbox/PrototypeJS libraries
 *	(peisenmann@gatech.edu)
 *
 * Modified by Andre Bluehs to support PHP (and any other user added extensions)
 *	(contagious@gatech.edu)
 */

// Do this when the document loads
$j(document).ready(function() {    
    // Id of the tag that will wrap the content
    var contentWrapID = '___content-wrapper';
        
    // Wrapping the content. This will keep us from duplicating the content div
    // This is an important change from James' script because his would not work
    // for Safari
    var wrapDiv = document.createElement("div");
    wrapDiv.id = contentWrapID;
    $j('#content').wrap(wrapDiv);
	$j('.hide-with-jQuery').css("display","none")	
var $ss = $j('#headerimg'); 
         
    // add slides to slideshow (images 1-3) 
    for (var i = 1; i < 4; i++) 
       $ss.append('<img src="/wp-content/themes/X2_Hosting/images/headerimg'+i+'.jpg" width="950px" height="250px" />'); 
 
    // start the slideshow 
    $ss.cycle({speed:5000, speedIn:500, speedOut:2500}); 

	
	
    
    // Once we've loaded the new content, show it
    function showNewContent() {
        // Show the wrapper that contains the content
        $j("#" + contentWrapID).slideDown();
        
        // Hide the ajax loader icon
        $j('#load').fadeOut();   
$j('.hide-with-jQuery').css("display","none")	
$j('.hide-with-jQuery div').css("display","none")	






    }


  // Adds the onclick function to the sidebar links
    $j('#content a[href*=://' + document.domain + ']').live('click',function(){
        
        // Get the hash from the link that was clicked
        var hash = $j(this).attr('href');
        hash = hash.replace(/^.*#/, '');
hash.replace('hosting','contact');


        // Load this hash with the history plugin
        $j.historyLoad(hash);
        
        if(!$j('#load').get(0)) {
            $j('#header').append('<span id="load">LOADING...</span>');
        }
        $j('#load').fadeIn('normal');
		
		//	EvD attach other effects to the newly loaded content
		
	
        return false;
    });

    
    // Load a page based on a hash (Given from the address bar)
    function pageload(hash) {
        // If the hash is not empty or undefined
        if(hash) {            
            // Hide the content
            $j("#" + contentWrapID).slideUp('slow',
                function()
                {
                    // Load the #content div from page of the mentioned in the hash
                    $j("#" + contentWrapID).load(hash + " #content",'',function (responseText, textStatus, XMLHttpRequest) {
					
                        
                        // Don't bother if the hash was busted
                        if (textStatus == "error") return;
                        
                        // This helps show the content only when it's all loaded
                        if($j('img:last',this).get(0)) {
                            $j('img:last',this).load(function(){
                                showNewContent();
                            });
                        } else {
                            showNewContent();
                        }

                    });
                }
            );


        } else {
            // Load this page
            pageload(window.location.href);
        }
    }
    // Initialize history
    $j.historyInit(pageload);
    
    // Adds the onclick function to the links
    $j('#nav li a').live('click',function(){
        
        // Get the hash from the link that was clicked
        var hash = $j(this).attr('href');
        hash = hash.replace(/^.*#/, '');
hash.replace('hosting','contact');


        // Load this hash with the history plugin
        $j.historyLoad(hash);
        
        if(!$j('#load').get(0)) {
            $j('#header').append('<span id="load">LOADING...</span>');
        }
        $j('#load').fadeIn('normal');
		
		//	EvD attach other effects to the newly loaded content
		
	
        return false;
    });
	
	//	show/hide all divs that are inside the div that cointains the .trigger class
	//$j('.trigger').click(function(event) {
		//event.preventDefault();$j(this.parentNode.getElementsByTagName('ul')).slideToggle();
//		event.preventDefault();$j(this.parentNode.getElementsByTagName('ul')).slideToggle();
		//event.preventDefault();$j(this.parentNode.getElementsByTagName('.box')).slideToggle();
//	}); 
	
	//	show/hide all divs that are inside the div that cointains the .trigger class. Also bind to future items
	$j('.trigger_div').live('click', function(event) {
		//event.preventDefault();$j(this.parentNode.getElementsByTagName('ul')).slideToggle();
		event.preventDefault();
		$j(this.parentNode.getElementsByTagName('div')).slideToggle('slow' );
		//event.preventDefault();$j(this.parentNode.getElementsByTagName('.box')).slideToggle();
}); 
	//	show/hide all divs that are inside the div that cointains the .trigger class
$j('.trigger_p').live('click',function(event) {
		//event.preventDefault();$j(this.parentNode.getElementsByTagName('ul')).slideToggle();
		event.preventDefault();$j(this.parentNode.getElementsByTagName('p')).slideToggle('slow' );
		//event.preventDefault();$j(this.parentNode.getElementsByTagName('.box')).slideToggle();
	}); 
//	$j('.box a').click(function(event) {
//		event.preventDefault();$j(this.parentNode.parentNode.getElementsByTagName('div')).slideUp();});
	
});
