$(document).ready(function(){ 
	//fix IE bugs
    $(document).pngFix();
    
    var zIndexNumber = 1000;
	$('div').each(function() { $(this).css('zIndex', zIndexNumber); zIndexNumber -= 10; });
    
	//fading stuff
	$('#sitedesc').innerfade({ speed: 1500, timeout: 5000, type: 'sequence', containerheight: '36px' });
	$('#start').innerfade({ speed: 1500, timeout: 6000, type: 'sequence', containerheight: '401px' });	
	$('#faqright').innerfade({ speed: 1500, timeout: 6000, type: 'sequence', containerheight: '401px' });	
		
	//scrollbars
	$('#aboutcontent').jScrollPane({scrollbarWidth: 7, showArrows: true});
	$('#faqcontent').jScrollPane({scrollbarWidth: 7, showArrows: true});
	$('#comments').jScrollPane({scrollbarWidth: 7, showArrows: true});
		//$('#ambcontent').jScrollPane({scrollbarWidth: 7, showArrows: true});
	$('#presscontent').jScrollPane({scrollbarWidth: 7, showArrows: true});
	$('#press_thumbs').jScrollPane({scrollbarWidth: 7, showArrows: true});
	
	//image carousels
	/*$("#carousel_start").jCarouselLite({ btnNext: ".start_next", btnPrev: ".start_prev", circular: true, visible: 1 });
	$("#carousel_0").jCarouselLite({ btnNext: ".start_next", btnPrev: ".start_prev", circular: true, visible: 1 });
	$("#carousel_1").jCarouselLite({ btnNext: ".start_next", btnPrev: ".start_prev", circular: true, visible: 1 });
	$("#carousel_2").jCarouselLite({ btnNext: ".start_next", btnPrev: ".start_prev", circular: true, visible: 1 });
	*/

	//$(".carousel").jCarouselLite({ btnNext: ".start_next", btnPrev: ".start_prev", circular: true, visible: 1 });
	
	//$('#carousel_elvis').hide();
	//$('#carousel_keith').hide();
	//$('#carousel_marie').hide();

	//$(".carousel").jCarouselLite({circular: true, visible: 1 });

	//$(".carousel").jCarouselLite({ btnNext: ".start_next", btnPrev: ".start_prev", circular: true, visible: 1 });
	
	js_slider({width : "348", height : "401"});
	
	$("div#collection ul li h4").click(function () { $("div#collection ul li h4").removeClass("highlight"); $(this).addClass("highlight"); });
	
	$("div#collection div#desc div").hide();

	var prevItems;
	$(".carousel").hide();
	$("#carousel_start").show();
	
	var i = 0;
	$(".carousel").each(function(){
		//$(this).jCarouselLite({ btnNext: ".start_next", btnPrev: ".start_prev", circular: true, visible: 1 });
		//$(this).jCarouselLite({ btnNext: ".next_" + i, btnPrev: ".prev_" + i, circular: true, visible: 1});
		//console.debug(this);
		i++;
	});
	
	$("#ambassador_right #button").click(function(){
		var ambName = $("#ambassadorName").val();
		var ambEmail = $("#ambassadorMail").val();
		//console.debug(ambName + " " + ambEmail);
		$.post("ambassadorMail.php", {email : ambEmail, name : ambName});
		
		$("#ambassadorName").val("");
		$("#ambassadorMail").val("");
		return false;
	});
	
	$(".collection_button").each(function(){
		$(this).click(function(){
			prevItems = $(this).prevAll(".collection_button");
			carouselNumber = prevItems.length;
			$(".carousel").hide();
			$("div.collection_desc").hide();
			$("#carousel_" + carouselNumber).show();
			$(".desc_"+carouselNumber).show();
		})
	});
	
	$(".reportComment").click(function(){
		var id = $(this).attr("id");
		id = id.replace(/comment_id_/, "");
		
		if($(this).text() == "Reported"){
			return false;
		}
		
		$.post("report.php", {id:id}, reportCallback);
		
		$(this).text("Reported");
	})
	
	
	$("#text").click(function() { if($(this).text() == "Comment") $(this).text(""); });
	resizePressContainter();
});

function resizePressContainter(){
	$("#press .jScrollPaneContainer").css("height", "230px");
}

function reportCallback(data){
	console.debug("reported");
	
}
// font replacing
	Cufon.replace('h1', { hover: true, fontFamily: 'calvert' });
	//Cufon.replace('h2', { hover: true, fontFamily: 'calvert' });
	Cufon.replace('h3', { hover: true, fontFamily: 'calvert' });
	Cufon.replace('h4', { hover: true, fontFamily: 'calvert' });
Cufon.replace('ol', { hover: true, fontFamily: 'calvert' });

var slideReady;
function js_slider(options){
	
	var width = options.width * 1;
	var height = options.height * 1;
	height -= 30;
	var horizontalPosition = 0;
	var theCounter = 0;
	
	$(".slider").css({
		"position" : "relative",
		"width" : width + "px",
		"height" : height + "px"
	});
	$(".slider img").css({
		"margin" : "0px",
		"padding" : "0px",
		"position" : "absolute",
		"top" : "0px"
	});

	$(".sliderButton").click(function(){
		return false;
	})
	
	
	$(".slider").each(function(){
		horizontalPosition = 0;
		var images = $(this).find("img");
		var nextButton = $(this).find(".next");
		var prevButton = $(this).find(".prev");
		
		var imagesTotal = $(this).find(".imagesTotal");
		var currentImage = $(this).find(".currentImage");

		var imagesArray = new Array();
		var theCounter = 1;
		var imagesCount;
		
		$(prevButton).hide();
		
		var j = 0;
		$(images).each(function(){
			$(this).css("left", horizontalPosition + "px");
			imagesArray.push($(this));
			horizontalPosition += width;
			j++;
		})
		
		imagesCount = j;
		
		$(imagesTotal).text(imagesCount);
		
		if(imagesCount <= 1){
			$(nextButton).hide();
		}
		if(imagesCount < 1){
			$(".currentImage").text("0");
		}
		
		$(prevButton).click(function(event){
			$(images).each(function(){
				var imageLeft = $(this).css("left");
				imageLeft = parseInt(imageLeft);
				newLeft = imageLeft + width;
				
				$(this).animate({"left" : newLeft + "px"},200);
			});
			theCounter--;
			$(currentImage).text(theCounter);
			$(nextButton).show();
			if(theCounter == 1){
				$(this).hide();
			}
		})
		
		$(nextButton).click(function(event){
			$(images).each(function(){
				var imageLeft = $(this).css("left");
				imageLeft = parseInt(imageLeft);
				newLeft = imageLeft - width;
				
				$(this).animate({"left" : newLeft + "px"},200);
			});

			theCounter++;
			$(currentImage).text(theCounter);
			$(prevButton).show();
			if(theCounter == imagesCount){
				$(this).hide();
			}
		})
		//console.debug(j);
	});
	
	
	
	/*$(".sliderButtons .next").click(function(){
		$(".slider img").each(function(){
			var imageLeft = $(this).css("left");
			imageLeft = parseInt(imageLeft);
			newLeft = imageLeft - width;
			
			$(this).animate({"left" : newLeft + "px"});
		});
		theCounter++;
		if(theCounter == (imagesCount - 1)){
			$(this).hide();
		}
	})*/

	/*$(".sliderButtons .prev").click(function(){
		$(".slider img").each(function(){
			var imageLeft = $(this).css("left");
			imageLeft = parseInt(imageLeft);
			newLeft = imageLeft + width;
			
			//$(this).css("left" , newLeft + "px");
			$(this).animate({"left" : newLeft + "px"});
			//console.debug(imageLeft);
		});
	})*/
}

