
// bind onclick event on  ObjectCart item to delete items


jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
	if ((t/=d) < (1/2.75)) {
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)) {
		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	} else if (t < (2.5/2.75)) {
		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	}
};




$(document).ready(function(){

	$('a.outsideLink').click(function(){
		var nid = this.id.replace('i','');
		var fid = $(this).parents().attr('id').replace('f','');
		$.ajax({
			type: "GET",
			url: _root + 'include/ajax/saveHits.asp',
			data: 'fid=' +fid+ '&nid=' +nid,
			success: function (data){
				//alert(data);
			}
		});
	});


	//----- header van carouselbanners aanpassen -----
	carouselHeader();
	



	$('body').focus(function(){
		//carouselHeaderOld();
	});
	
	
	function mycarousel_initCallback(carousel){
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});
	
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});
	
		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	};
	
	
	
	
	var nScroll	= 0
	var first	= true
	var banner	= 0
	var active	= 0
	
	function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt){
		var idx = carousel.index(i, 4);
		var bannerText	= ('<div class="carouselText">'+$('#text-'+idx).html()+'</div>')
		
		carousel.add(i,bannerText);
		//carouselHeaderOld();
	};

	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt){
		carousel.remove(i);
	};
	function mycarousel_after(carousel, item, i, state, evt){
		$("#roundedCarousel > .curSlide  > li").removeClass("active");
		var idx = i
		var dif = (idx-banner)
		
		active += dif
		
		if (active==0){
			active=4
		}
		if (active==5){
			active=1
		}
		banner = i
		$("#cs-"+active).toggleClass("active");
		
		
		
		if (active==4 && first==true){
			carousel.startAuto();
			first = false
		}
		else if (first==false){
			carousel.stopAuto();
		}
	}
	
	jQuery('#mycarousel').jcarousel({
		auto: 6,
		wrap: 'circular',
		scroll: 1,
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback, onAfterAnimation:mycarousel_after},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
		initCallback: mycarousel_initCallback
	});
	




	//----- header van pagina's -----
	$('#pageHeader h1').each(function(i){
		var h1 		= ($(this).html())
		var newh1 	= '<span class="h1Front">' +h1+ '</span><span class="h1Shade">' +h1+ '</span>'
		$(this).html(newh1)
	});
	
	//----- header van carouselbanners aanpassen -----
	//carouselHeaderOld();
	
	
	
	var jBrowser = 'msie'
	var jVersion = '7.0'
	//--- browser + version ophalen ---
	jQuery.each(jQuery.browser, function(i, val) {
		if (i=='version'){
			jVersion = val
		}
		if (val==true){
			jBrowser = i
		}
	});
	
	//----- Buttons maken van links met class=RPbutton -----
	$('a.RPbutton').each(function(i){
		$(this).prepend('<div class="linkRight"></div>');
		
			//Bij IE6 iets anders...
			if (jBrowser=='msie' && jVersion=='6.0'){
				var aW = $(this).width();
				$(this).css({
					'width':(aW+'px'),
					'display':'block',
					'paddingTop':'0px',
					'paddingBottom':'0px'
				});
			}
	});
	
	
	
	//--- promocodes toevoegen ---
	$('#addPromocode').click(function(){
		var nMaxPromo	= 10
		var oTD 		= $(this).parents('td');
		var sI			= $(oTD).children('input[type=text]').size();
		
		if (sI<nMaxPromo){
			var oI			= $(oTD).children('input[type=text]:first');
			var name		= $(oI).attr('name');
			var c			= $(oI).attr('class');
			var ml			= $(oI).attr('maxlength');
			
			var newInput 	= '<br><input class="' +c+ '"  name="' +name+ '" type="text" value="" maxlength="' +ml+ '">'
			$(oTD).append(newInput);
		}
		else{
			alert(lang_max_promocode);
		}
	});
});




	function carouselHeader(){
		$('.tmpCarouselTxt').each(function(i){
			var bFirst		= false
			var obj			= $(this)
			var txt 		= obj.html();
			var matchTxt 	= txt.match('h1Front');
			
			var bChecked	= false
			if (matchTxt!=null){
				bChecked	= true
			}
			
			if (!bChecked){
				var id = obj.attr('id');
				
				$('#'+id+' p font').each(function(j){
					var o = $(this);
					
					if (!bFirst){
						h1 	= o.html();
						if ((o.hasClass('Kop1')==true)||(o.hasClass('kop1')==true)){
							isKop1 = true
						}
						
						var html 		= obj.html();
						var matchHtml 	= html.match('h1Front');
						if (matchHtml!=null){
							isKop1	= false
						}
					
						if (isKop1==true){
							o.remove();
							
							var innerH1 = '<span class="h1Front">' +h1+ '</span><span class="h1Shade">' +h1+ '</span>'
							obj.prepend('<h1>' +innerH1+ '</h1>');
							bFirst = true
						}
					}
				});
			}
		});
	}
	
	
	function carouselHeaderOLD(){
		//----- header van carouselbanners aanpassen -----
		
		//var s = $('ul#mycarousel li .carouselText').size();
		//alert('s = '+s);
		
		
		
		
		$('ul#mycarousel li .carouselText').each(function(i){
			var txt 		= $(this).html();
			var matchTxt 	= txt.match('h1Front');
			
			var bChecked	= false
			if (matchTxt!=null){
				bChecked	= true
			}
			alert('txt = ' + txt + '\nmatchTxt = ' + matchTxt + '\nbChecked = ' + bChecked);
														  
														 
			//alert('i = '+i);
			if (!bChecked){
				var h1 = ''
				var isKop1 = false
				$(this).attr({id:('slideText'+i)});
				var bFirst		= false
				
				
				var h = $('#slideText'+i+' p:first font').html();
				//alert('h = '+h);
				
				
				
				$('#slideText'+i+' p font').each(function(j){
					var o = $(this);
					//alert('this.html = ' + $(this).html() + '\nbFirst = ' + bFirst)
					
					if (!bFirst){
						h1 	= o.html();
						if ((o.hasClass('Kop1')==true)||(o.hasClass('kop1')==true)){
							isKop1 = true
						}
						//alert('class = ' + o.attr('class'))
						
						var html 		= $('#slideText'+i).html();
						var matchHtml 	= html.match('h1Front');
						if (matchHtml!=null){
							isKop1	= false
						}
						//alert('j = '+j);
					
						//if ((h1!='')&&(isKop1==true)){
						if (isKop1==true){
							//$('#slideText'+i+' p:first').remove();
							o.remove();
							
							//alert($('#slideText'+i+' p:first').html());
							
							var innerH1 = '<span class="h1Front">' +h1+ '</span><span class="h1Shade">' +h1+ '</span>'
							//alert('innerH1 = '+innerH1);
							$('#slideText'+i).prepend('<h1>' +innerH1+ '</h1>');
							bFirst = true
							var html = $('#slideText'+i).html();
							//alert('html = '+html);
						}
					}
				});
			}
		});
	}

				
jQuery.fn.slideFadeToggle = function(speed, easing, callback){
	return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);  
};
function OnEnter(e){
	if (event.keyCode==13){
		document.qLoginFrm.submit();
		return false;
	}
}






