$(document).ready(function(){
	
//INNER TABS
	$("ul.innertabs > li > a").bind('click', function (){
		if ($(this).hasClass("active")) {
			return false;
		} else {
			$("ul.innertabs>li>a").removeClass("active");
			$(this).addClass("active");
			var colorid = $(this).parent().attr("class");
			$("#content_bar").attr("class", colorid);
			$("img.img").hide();
			$('img[id=' + colorid +']').fadeIn(300);
			return false;
		};
	});
	
//MODAL WINDOW
	//determine top scroll position if relevant - fixes IE
	function f_scrollTop() {
		return f_filterResults (
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0
		);
	}
	function f_filterResults(n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}
	
	//apply to all a tags with name equal to modal  
    $('a[name=modal]').click(function(e) {
		e.preventDefault();
		//alert(f_scrollTop());
		var id = $(this).attr('href');
		
        //Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
		
        //Set height and width to mask to fill up the whole screen
		$('#overlay').css({'width':'100%','height':maskHeight});
        
        //transition effect
		$('#overlay').fadeIn(200);
		
        //Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2+f_scrollTop());
		$(id).css('left', winW/2-$(id).width()/2);
//		$(id).css('top',  winH/2-$(id).height()/2+document.body.scrollTop);
		//transition effect
		$(id).fadeIn(200);
	});
	
	//if close button is clicked
	$('div[id^=needle_modal] .close').click(function (e) {
		e.preventDefault();
		$('#overlay').fadeOut(100);
		//fade out all divs with an ID prefix of "needle_modal"
		$('div[id^=needle_modal]').fadeOut(100);
	});
	
	//if mask is clicked
	$('#overlay').click(function () {
		$(this).hide();
		//fade out all divs with an ID prefix of "needle_modal"
		$('div[id^=needle_modal]').fadeOut(100);
	});
	
//MODAL CONTENT
	$(".modal_content > a").bind("click", function(e) {
		e.preventDefault();
	});
	$(".modal_content > a").bind("mouseover", function() {
		var modal_id = $(this).attr('id');
		$("#detail_info > p").hide();
		$('p[class='+ modal_id +']').show();
		return false;
	});
	$(".modal_content > a").bind("mouseout", function() {
		$("#detail_info > p").hide();
		$('#default').show();
		return false;
	});

	//Contact submission validation
	$('.contact_form').submit( function(e){
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('email');
		var name = $("#name").val().length;
		if (!filter.test(email.value)) {
			$('.email_missing').show();
		} else {$('.email_missing').hide();}
		if (name < 1) {
			$('.name_missing').show();
		} else {$('.name_missing').hide();}	
		if ((name < 1) || (!filter.test(email.value))){
			return false;
		}
	});
});

