/* Author: Ryan Duffy

*/

$(function(){

	// This initialises carousels on the container elements specified, in this case, carousel1.
	$("#carousel1").CloudCarousel(		
		{			
			xPos: 480,
			yPos: 60,
            xRadius: 310,
            yRadius: 50,
            minScale: 0.79,
			buttonLeft: $("#left_but"),
			buttonRight: $("#right_but"),
			altBox: $("#alt-text"),
			titleBox: $("#title-text")
		}
	);


	$(".nav>ul>li").mouseover(function(){
		$(this).children("ul").slideDown("fast");
		$(this).children("a").addClass("hover");
	});
	
	$(".nav>ul>li").mouseleave(function() {
		$(this).children("ul").hide();
		$(this).children("a").removeClass("hover");
	});
	
	$(".sub-tabs a").click( function() {
		console.log("#"+$(this).html());
		$(".sub-tabs a").removeClass("active");
		$(this).addClass("active");
		$(".list").hide();
		$("#"+$(this).html()).show();
	});
	

	
	function doVertTabs(clicked, which) {
		$(clicked).parent().children("li").removeClass("active");
		//console.log($(clicked).parent().children("li"));
		$(clicked).parent().children("li:nth-child("+which+")").addClass("active");
		//console.log($(clicked).parent().children("li:eq("+which+")"));
		$(clicked).closest(".vert-tabs-container").children(".tabs-panels").children("div").hide();
		//console.log($(clicked).closest(".vert-tabs-container").children(".tabs-panels").children("div"));
		$(clicked).closest(".vert-tabs-container").children(".tabs-panels").children("div:nth-child("+which+")").show();
		//console.log($(clicked).closest(".vert-tabs-container").children(".tabs-panels").children("div:nth-child("+which+")"));
	}
	$(".tabs-vertical li").click(function() {
		doVertTabs($(this),$(this).index()+1);
	});
	
	$(".tabs-vertical li:first-child").each(function() {
		doVertTabs($(this),$(this).index()+1);
		//console.log($(this));
	});	
	
	$(function(){
        $("input, textarea, select, button").uniform();
      });
    $("#contact-form").validate();
    
    $("#phone").click(function() {
    	var highest = 1;
    	$('#carousel1 div a img').each(function() {
	    	
	    	if(parseInt($(this).css("z-index")) > highest) {
	    		console.log($(this).css("z-index")+"was greater than "+highest)
	    		highest = $(this).css("z-index");
	    	}
    	});
    	console.log('highest: '+highest);
//    	document.location.href = $('#carousel1 div a img').filter(function() {
//		     return $(this).css('z-index') == highest;
//		}).parent("a").attr("href");
    	document.location.href = $('#carousel1 div a img').filter(function() {
		     return $(this).css('z-index') == highest;
		}).parent("a").attr("href");
    });
	
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});

	
});





















