$(document).ready( function(){
	// Make maincontent div rounded corners
 //	$('.rounded').corners('10px');
	
	/* $('#maincontent').css({'display':'none'}); */
	
	//set effect from select menu value
	$("#info-button").mouseenter(function() {
		$("#maincontent").stop(1,1).toggle('fold','',500);
		return false;
	});
	
	var home = 0;
	var l = window.location.hash;
	if(l == '#home.html' || l == '' ){
		// Page is the home page
		home = 1;
		$('#maincontent').delay(1500).toggle('fold','',500).width(450);
	} else {
		home = 0;
		$('#maincontent').delay(1500).toggle('fold','',500).width(630);
	}
	
	/* Chooses event to be used in the main ment tabs */
	var event = 'click';	/* click or mouseover */
	
	$('div#loading').ajaxStart(function(){
		$(this).fadeIn('slow');
	}).ajaxStop(function(){
		$(this).fadeOut('slow');
	});
	
	

	// Load new page from menu via AJAX using tabs() function in jquery Tools....      
  	$("ul.menu").tabs("div#maincontent > div", {
  		effect: 'ajax',
  		event: event,
  		tabs : 'a',
  		onBeforeClick : function(){
  			//$("div#loading").css({'display':'block'});
  		},
  		onClick : function(){
  			//$("div#loading").css({'display':'none'});
  			$('#menu li a').removeClass('active');
			$('.current').toggleClass('active'); 
			$('#maincontent').scrollTop(0);
  		}}).history(); 
  	
/*
  	// Disable clicking of links
	$('#menu li a').click( function() { 
		$('#menu li a').removeClass('active');
		$('.current').toggleClass('active');
		return false; 
	}).hover(function(){ 
	//	$('#menu li a').removeClass('active'); 
	//	$(this).addClass('active');
	});
*/

	// Change css for div#maincontent depending on page loaded
	$('.menu li a').hover(function() {
		if(event=='mouseover'){
			if($(this).attr('href') != 'home.html'){
	         	$('#maincontent').width(630).show('fold','',500);
	          } else {
	         	$('#maincontent').width(400).hide('fold','',500);	         	
			}
		}
	}).click(function(){
		if(event=='click'){
			if($(this).attr('href') != 'home.html'){
	         	$('#maincontent').width(630).show('fold','',500);
	          } else {
	         	$('#maincontent').width(400).hide('fold','',500);	         	
			}
		}
		if(event == 'mouseover' ){ return false; }; 
	});
	
	
	
	


	// create custom animation algorithm for jQuery called "bouncy" 
	$.easing.bouncy = function (x, t, b, c, d) { 
    	var s = 1.70158; 
	    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
    	return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	} 
 
	// create custom tooltip effect for jQuery Tooltip 
	$.tools.tooltip.addEffect("bouncy", 
 
    	// opening animation 
	    function(done) { 
    	    this.getTip().animate({top: '+=15'}, 500, 'bouncy', done).show(); 
	    }, 
 
    	// closing animation 
	    function(done) { 
    	    this.getTip().animate({top: '-=15'}, 500, 'bouncy', function()  { 
        	    $(this).hide(); 
            	done.call(); 
	        }); 
    	} 
	);
	
	

});


// slide show function
function slideSwitch() {
	
    var $active = $('.slideshow IMG.show');

    if ( $active.length == 0 ) $active = $('.slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('show')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('show last-active');
        });
}

function specialOffer(){
	// slides special offer pics
    var $active = $('#special-offer IMG.show');

    if ( $active.length == 0 ) $active = $('#special-offer IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#special-offer IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active').animate({ opacity : 'hide' },1500,function(){
    	$next.animate({opacity: 'show'}, 1500, function() {
            $active.removeClass('show last-active');
        }).addClass('show');
    });

    
}


$(function() {
	setInterval( "slideSwitch()", 2500 );	
	setInterval( "specialOffer()", 8000 );
//	specialOffer();
});
