/*
----- Made by WebForceOne ------------------
----- http://www.www.webforceone.nl --------
----- Contact: info@webforceone.info -------
----- Telephone: 070 767 00 43 -------------
*/

var admin_url = "http://beheer.webforceone.info/obviouscat/";
var base_url = "http://www.obviouskappers.nl/";

// ResizeRight --------------------------
function ResizeRight() {
	
	var height = $(".links").height();
	var height2 = $(".rechts").height();
	
	if (height2 < height) {
	$(".rechts").css("height", height+"px");
	}
	
}

// Position Lipje ------------------------
function Lipje() {
	
	var pos = $("#header .menu li.active").offset(); 
	
	var width = $("#header .menu li.active").width(); 
	var width_berekend = pos.left - width;
	
	$(".lipje").css("left",width_berekend+"px");	
}

// Make Ticks --------------------------
function MakeTicks() {
	
	Items = $(".items li").size();
	Ticks = $(".ticker .tick").size();
	
	// Make Ticks	
	for (var i=0; i<Items-1; i++){
		$('.tick:first-child').clone().appendTo('.ticker');
	}
	
}

// NextTick --------------------------
function NextTick(){
    
}

// ShowCart ------------------------------
function ShowCart() {
	
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
  		return this.animate({opacity: 'toggle'}, speed, easing, callback);  
	};
	
	$(".cart_inhoud").fadeToggle(300); 
		
}

// CartItems
function LoadCartItems() {
	
	$.ajax({
	    type: "POST",
	    url: "http://www.obviouskappers.nl/include/cart.php",
	    data: "subject=LaatCartZien",
		success: function(html) {
			$(".cart_inhoud").html(html);
		}
	});
}

// CartAantal
function LoadCartAantal() {
	
	$.ajax({
	    type: "POST",
	    url: "http://www.obviouskappers.nl/include/cart.php",
	    data: "subject=CartAantal",
		success: function(html) {
			$(".sub_menu .cart .bullet .midden").html(html);
		}
	});
	
}

// Delete uit de wagen
function Verwijder(Id) {

	$.ajax({
	    type: "POST",
	    url: "http://www.obviouskappers.nl/include/cart.php",
	    data: "subject=DeleteUitCart&pid="+ Id,
		success: function(html) {
			$("#cart_item-"+Id).slideUp(300, function() {
				LoadCartItems();
				LoadCartAantal();
				ShakeBullet();
			});
		}
	});
}

// ShakeBullet
function ShakeBullet() {
	
	$(".sub_menu .cart .bullet").animate({opacity: 0.25},100, function() {
    	$(".sub_menu .cart .bullet").animate({opacity: 1},200);
  	});

}

// Body onload
$(document).ready(function() {
			
	// ResizeRight
	ResizeRight();
	
	// Make Ticks
	MakeTicks();
	
	// Set Lipje
	Lipje();
	
	// Make first Tick Active
	$(".ticker .tick:first-child").addClass("tick_a");
		
	// Make Active Tick
	$(".ticker .tick").click(function() {
		
		// Li Number
		LiNumber = $(this).index();
		
		// Animate in
		$(this).animate({opacity: 0.25},100, function() {
    		$(".ticker .tick").removeClass("tick_a");
			$(this).addClass("tick_a");
  		}); 		
  		
  		// Action
  		$(".items").scrollTo("li:eq("+LiNumber+")", 1500);
  		
  		// Animate out	
		$(this).animate({opacity: 1},300);
	});
	
	// Hover Thumbs
	$(".thumb").click(function() {
		
		var hoofdname = $(this).attr('title');
		
		// Animate In
		$(".hoofd_foto").animate({opacity: 0.0},200, function() {
    		$(".hoofd_foto").css("background-image", "url("+admin_url+"upload/catalogus/"+hoofdname+")");
  		}); 
		
		// Animate Out
		$(".hoofd_foto").animate({opacity: 1},400);
		
	});
	
	// Hover Pijl
	$(".voeg_toe").hover(
		function () {
			$(".pijl").animate({top: "58"},200);
		},
		function () {
			$(".pijl").animate({top: "48"},200);
		}
	);
	
	// Voeg toe aan de wagen		
	$(".voeg_toe").click(function(){
		
		var Id = $(".voeg_toe").attr("id");
		var p_aantal = $("#p_aantal").val();
		
		$.ajax({
		    type: "POST",
		    url: "http://www.obviouskappers.nl/include/cart.php",
		    data: "subject=VoegToeAanCart&pid="+ Id +"&p_aantal="+ p_aantal,
			success: function(html) {
				$(".cart_inhoud").html(html);
				LoadCartAantal();
				ShakeBullet();
			}
		});
							    	
    });
    
    $(".werkbij").click(function(){
    	$("form:first").submit();
    }); 	
	
	$(".afrekenen").click(function(){
    	$("form:second").submit();
    }); 
	
	// Placeholders Switch Text
	function switchText() {
		
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
			$(this).css("color","black");
		} else if ($.trim($(this).val()) == '') {
			$(this).val($(this).attr('title'));
			$(this).css("color","silver");
		}
	}
	
	$('input[type=text][title != ""]').each(function() {
		
		if ($.trim($(this).val()) == '') {
			$(this).val($(this).attr('title'));
			$(this).css("color","silver");
		}
		
	}).focus(switchText).blur(switchText);
	
	$('form').submit(function() {
		$(this).find('input[type=text][title != ""]').each(function() {
			if ($(this).val() == $(this).attr('title')) {
				$(this).val('');
			}
		});
	});
	
	// Load eerste keer	
	LoadCartItems();
	LoadCartAantal()
	
	// Search Producten on KEYUP
	$("#zoek_functie").keyup(function() {
				
		var Content = $(this).val();
		var charLength = $(this).val().length;
                
        if (charLength > "2") { 
			
			$("#zoek_data").fadeIn(300);
						
			$.ajax({
			    type: "POST",
			    url: "http://www.obviouskappers.nl/zoek.php",
			    data: "zoek="+ Content,
				success: function(data) {
					$("#zoek_data").html(data);
				}
			});
					
		} else {
			// Doe niks
		}
		
		if (charLength == 0) {
			$("#zoek_data").slideUp(300);
			$("#zoek_data").html("");
		}
		
	});
	
	
});
