jQuery.noConflict();

jQuery(document).ready(function(){
// noConflict function, this enables us to use mootools with jQuery	

	jQuery("#nav > li").addClass("parent");
	jQuery("#nav li a").click(function(){
		jQuery("#nav > li > a").removeClass("current");	
		jQuery(this).closest("li.parent").children("a").addClass("current");
	});
	
	jQuery("#footer div a").click(function(){
		jQuery("#nav > li > a").removeClass("current");	
		jQuery("#nav li." + jQuery(this).closest("div").attr("id").substring(7) + " > a").addClass("current");
	});
	
	jQuery("#nav li").has("ul").hover(function(){
		jQuery(this).children("ul").show();
	}, function() {
		jQuery(this).children("ul").hide();
	});
	
	jQuery("#nav ul").hover(function(){
		jQuery(this).show();
	}, function() {
		jQuery(this).hide();
	});

	
	// Carousel	
	// loop function
	jQuery.fn.timer = function(time) {
		//var a=new Date();
		//alert((a.getTime()-time)/1000);
		if(jQuery("#carousel-wrapper > div:last").is(":visible")){
			jQuery("#carousel-wrapper > div:visible").fadeOut(function(){
				jQuery("#carousel-wrapper > div:first").fadeIn();
			});
		}
		else{
			jQuery("#carousel-wrapper > div:visible").fadeOut(function(){
				jQuery(this).next().fadeIn();	
			});
		}
	} // timer function end

	// Loop
	if (window.time === undefined) {
		var d=new Date();
		time	=	d.getTime();
	}
	if (window.loop === undefined) {
		window.loop = setInterval(function(){jQuery("#carousel").timer(time)}, 10000);
	}
	// Controls
	jQuery("#carousel-controls #next").click(function(loop){
		jQuery("#carousel").timer(time);
		window.loop = clearInterval(window.loop);
		if (window.loop === undefined) {
			window.loop = setInterval(function(){jQuery("#carousel").timer(time)}, 10000);
		}
	});
	
	jQuery("#carousel-controls #prev").click(function(loop){
		jQuery("#carousel").timer(time);
		window.loop = clearInterval(window.loop);
		if (window.loop === undefined) {
			window.loop = setInterval(function(){jQuery("#carousel").timer(time)}, 10000);
		}
	});


// Tabs
	jQuery(".tab-1").click(function(){
		jQuery("#tabs > div").css("display", "none");
		jQuery("#tab-1").css("display", "block");
		return false;
	});
	
	jQuery(".tab-2").click(function(){
		jQuery("#tabs > div").css("display", "none");
		jQuery("#tab-2").css("display", "block");
		return false;
	});
	
	jQuery(".tab-3").click(function(){
		jQuery("#tabs > div").css("display", "none");
		jQuery("#tab-3").css("display", "block");
		return false;
	});
	
// Accordion
	jQuery("#accordion li a.accordion-toggle").siblings().hide().end().click(function(){
		jQuery(this).siblings().slideToggle(500);
		jQuery(this).toggleClass("active");	
		return false;
	});
	
// Gallery
if(jQuery("#gallery").length){
		
		// Fancybox
		jQuery("#gallery li a").fancybox({
			'titleShow'		: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
		
		// Variables aren't use properly due to Webkit
		var jQuerytotalImages = jQuery("#gallery > li").length, 
			jQuerytotalMargin = jQuerytotalImages * 6,
			jQuerywidth = jQuery("#gallery > li:first").width();
			jQuerytotalWidth = jQuerywidth * jQuerytotalImages + jQuerytotalMargin,
			jQueryvisibleWidth = jQuery("#gallery > li").width() * 7 + 6*7,
			jQuerystopPosition = (jQuerytotalWidth - jQueryvisibleWidth);
		
		// Webkit isn't handling variables - So ignore it
		if (!jQuery.browser.webkit) {
			jQuery("#gallery").width(jQuerytotalWidth);
		}
		
		jQuery("#gal-prev").click(function(){
			if(jQuery("#gallery").position().left < 0 && !jQuery("#gallery").is(":animated")){
				jQuery("#gallery").animate({left : "+=95px"});
			}
			return false;
		});
		
		jQuery("#gal-next").click(function(){
			if(jQuery("#gallery").position().left > ((jQuery("#gallery > li:first").width() * jQuery("#gallery > li").length + (jQuery("#gallery > li").length * 6)) - (jQuery("#gallery > li").width() * 7 + 6*7)) * -1 && !jQuery("#gallery").is(":animated")){
				jQuery("#gallery").animate({left : "-=95px"});
			}
			return false;
		});
	}

jQuery("div.back-to-top").click(function(){
	jQuery('html, body').animate({scrollTop:0}, 'fast');
	});

// fancyBox swf file	
jQuery(".flash").fancybox({
	    'padding'           : 0,
	    'autoScale'     	: false,
	    'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});


});
