$(document).ready(function () {  
  
	if( navigator.userAgent.match(/Android/i) ||
		navigator.userAgent.match(/webOS/i) ||
		navigator.userAgent.match(/iPhone/i) ||
		navigator.userAgent.match(/iPod/i) ||
		navigator.userAgent.match(/iPad/i)
	){
		// Do nothin here.
		//alert('this is a mobile device');
	}else{
		var top = $('#box-contact').offset().top - parseFloat($('#box-contact').css('marginTop').replace(/auto/, 0));
		$(window).scroll(function (event) {
		    // what the y position of the scroll is
		    var y = $(this).scrollTop();
		  	//alert(y);
		    // whether that's below the form
		    if (y >= (top - 30)) {
		      // if so, ad the fixed class
		      $('#box-contact').addClass('fixed');
		    } else {
		      // otherwise remove it
		      $('#box-contact').removeClass('fixed');
		    }
		});
	}
	
	
	//initalize the testimonials (now artist quotes).
	$("div.testimonial").hide().first().show().addClass("current").next().addClass("next");
	setInterval('changeTestimonial()', 4000);  
  
  
	//the back to top button script
	$("#but-arrow").hover(function() {
		$(this).find("span").animate({opacity: "show", top: "-35"}, "slow");
	}, function() {
		$(this).find("span").animate({opacity: "hide", top: "-45"}, "fast");
	});
	
	
	//initialte the light boxes
	$(".lb-iframe").fancybox({
			'overlayColor'	: '#000',
			'padding'		: 10,
			'width'		: 700,
			'height'		: 700,
			'autoScale'		: true,
			'transitionIn'	: 'elastic',
			'type'			: 'iframe',
			'transitionOut'	: 'elastic',
			'centerOnScroll': 'true'
		});
	$(".lb-ajax").fancybox({
			'overlayColor'	: '#000',
			'padding'		: 10,
			'width'		: 700,
			'height'		: 700,
			'autoScale'		: true,
			'transitionIn'	: 'elastic',
			'type'			: 'ajax',
			'transitionOut'	: 'elastic',
			'centerOnScroll': 'true'
		});
	$(".lb-gallery li a").fancybox({
			'overlayColor'	: '#000',
			'padding'		: 10,
			'autoScale'		: true,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'centerOnScroll': 'true'
		});
		
	
		
	//add last class to galleryitems
	$('.showcase-gallery ul li:nth-child(4)').addClass('last');
	$('.showcase-gallery ul li:nth-child(8)').addClass('last');
	$('.showcase-gallery ul li:nth-child(12)').addClass('last');
	$('.showcase-gallery ul li:nth-child(16)').addClass('last');
		
	//sub section js
	var currentPage = window.location.hash.replace("#", "");
	//alert(currentPage);
	showSubPage(currentPage);
	$('#sub-menu li a').click(function(){
		var newPage = $(this).attr('href').replace("#", "");
		showSubPage(newPage);
		//var currentscrollpos = $(window).scrollTop();
		//alert(currentscrollpos);
		//$(window).scrollTop() = currentscrollpos + 20;
		//window.location.hash = newPage;
		//window.location.replace(newPage);
		$("html, body").stop().animate({ scrollTop: $('ul#sub-menu').offset().top }, 400);
		//return false;
	});	
	
	
	//hide brand li without links
	$('ul.list-brand li a').each(function(){
		//alert($(this).attr('href'));
		if($(this).attr('href')=="" || $(this).attr('href')=="#" || $(this).attr('href')=="/")
		{
			$(this).parent().parent().hide();
		}
	});
	$('ul.list-brand li img').each(function(){
		//alert($(this).attr('href'));
		if($(this).attr('src')=="" || $(this).attr('src')=="/")
		{
			$(this).parent().hide();
		}
	});
	
	
	
});

function showSubPage(page){
	//show the sub page
	$("#content-tabs .category").hide();
	if (page == "")
	{
		page = $("#content-tabs .category").first().attr('id');
	}else{
		$("html, body").stop().animate({ scrollTop: $('ul#sub-menu').offset().top }, 400);
	}
	$('#' + page).fadeIn();
	//fix up the navigation
	$('#sub-menu li').removeClass('active').find('a').each(function () {
		if($(this).attr('href') == ('#' + page))
		{
			$(this).parent().addClass('active');
		}	
	});
}



function changeTestimonial(){
	$("div.testimonial.current").css({ opacity: 1 }).stop().hide().removeClass("current");
	$("div.testimonial.next").css({ opacity: 1 }).stop().fadeIn().removeClass("next").addClass("current");
	if ($("div.testimonial.current.last").length > 0)
	{
		$("div.testimonial.first").addClass("next");
	}else{
		$("div.testimonial.current").next().addClass("next");
	}
		
}
