$(document).ready(function() {
    
        //$("#container").hide(0).fadeIn(500);
        
        $("#mailResult")
        .fadeIn(1500)
        .delay(2000)
        .fadeOut(500);
        
        
        $(".songlist li").hover(function(){
            
            firstSrc = $(this).children("img").attr("src");
            secondSrc = firstSrc.replace("spotify_play", "spotify_play2");
            
          $(this).children("img").attr("src", secondSrc);  
        }, function(){
          $(this).children("img").attr("src", firstSrc);  
        });
        

	////////////////////////////////////////////

	
	$("a").hover(
		function() {
			$(this)
			.animate({
			color: "#ccc" }, 50);
			},
		function() {
			$(this)
			.animate({ 
			color: "#606589" }, 70);		
			});
	
	//////////////////////////////////////
	
	// Clear searchBox
	$('input, textarea').not("#btnSend").not(".cartProdNum").one("focus", function() { // '#searchBox'
	$(this).val("").css("color", "#444444");
	});
	
	
	//////////////////////////////////////
	
	
	$(".galleryViewer").click(
		function(){

			galleryId = $(this).attr("id");
			numOfImages = $(this).attr("alt");

		var viewer = new PhotoViewer();
		viewer.enableAutoPlay();
		for (var i = 1 ; i <= numOfImages ; i++) {
			if (i < 10) { pic = "0"+i; } else { pic = i; }
		viewer.add('media/galleries/' + galleryId + '/image' + pic + '.jpg');
		}
		
		void(viewer.show(0));
		
		});
	
	

	///////////////////////////////////////
	
	$("#topNav li").hover(
		function() {

			$(this)
			.animate({
			color: "#aaaaaa" }, 180 );
			$(this).children()
			.animate({
			color: "#aaaaaa"}, 180);
			},
						
		function() {

			$(this)
			.animate({ 
			color: "#606589" }, 300 );
			$(this).children()
			.animate({
			color: "#666" }, 300);			
			
			});
	
	///////////


	// // // //... S H O P

	$("[id^=addProd]").not("#addProd1").click(
		function() {
			
			clickID = $(this).attr("id");
                        pureID = $(this).attr("id").replace("addProd", "");
			hiddenProd = $("#" + clickID.replace("add", "cart"));
			hiddenNum = $("#" + clickID.replace("add", "cart") + "Num");
			btnPlus = $("#" + clickID.replace("add", "editPlus"));
			btnMinus = $("#" + clickID.replace("add", "editMinus"));
		
		// show prod img
		$(hiddenProd).fadeIn("slow");
                $("#shopLi" + pureID).fadeIn("slow");
		
		// add quantity
		existingNum = parseInt($(hiddenNum).val());
		$(hiddenNum).val(existingNum + 1);
		$(hiddenNum).fadeIn("slow");
		
		// objNum++
		numOfObjects = parseInt($("#cartTotalNum").html());
		$("#cartTotalNum").html(numOfObjects + 1);
		
		// show edit buttons
		$(btnPlus).fadeIn("slow");
		$(btnMinus).fadeIn("slow");
                
                updateTotalNum();
		
	});

	$("[id^=editPlus]").click(
		function() {		
			inputToEdit = ($(this).attr("id").replace("editPlus", "cart")) + "Num";
			newNum = parseInt($("#" + inputToEdit).val()) + 1;
			$("#" + inputToEdit).val(newNum);
			updateTotalNum();			
		});

	$("[id^=editMinus]").click(
		function() {		
			inputToEdit = ($(this).attr("id").replace("editMinus", "cart")) + "Num";
                        
			newNum = parseInt($("#" + inputToEdit).val()) - 1;				
			
			if (newNum <= 0) {
                                newNum = 0;
                                removeCartItem( $(this).attr("id").replace("editMinusProd", "") );
				
				}
			
			$("#" + inputToEdit).val(newNum);
			updateTotalNum();		
		});



	function updateTotalNum() {
		
		totalNum = 0;
		
		$("[id^=cartProd]").each(function() {	
				
			if ($(this).hasClass("cartProdNum")) {
				valueToAdd = parseInt($(this).val());
				totalNum = totalNum + valueToAdd;
			}
		});
		$("#cartTotalNum").html(totalNum);
                
                var newPrice = (parseInt(totalNum) * 8.99);
                $("#cartTotalPrice").html(newPrice);
                
	}
        
        function removeCartItem(itemToRemove) {
            $("#shopLi" + itemToRemove).fadeOut("fast");
        }
        

	
	$("#facebook-box").fbWall({
		id:'lavaengine',
		accessToken:'235035199879884|fVezn6_1Fh8t7EuWNSn8Pd9u3TQ', 
		showGuestEntries:false,
		showComments:true,
		max:5,
		timeConversion:24 
	});


	    $("#query").tweet({
	      avatar_size: 30,
	      count: 15,
	      query: "lavaengine",
	      loading_text: "searching twitter...",
		  refresh_interval: 60 }
		);


	//////////


	
			
});
