
function wc()
{
	if(window.console)
	{
		for(var i = 0; i < arguments.length; i++)
		{
			window.console.log(arguments[i]);
		}
	}
}


$(document).ready(function()
{
	
	
	
		
		
		
		
	/*
	| --------------------------------------------------------------------------------------------
	| PNG fix crappy IE6
	| --------------------------------------------------------------------------------------------
	*/
	
	$(document).pngFix();

	/*
		Char count  
	*/
	
	var stdText = $('#tx_mailform_label_textarea').text();
	var maxLength=500;
	
	
	$('#tx_mailform_input-item-0-6').live('keyup', function(){
		var breaks = $('#tx_mailform_input-item-0-6').val().split("\n").length;
		var newlines = breaks - 1;
		counter = maxLength - $('#tx_mailform_input-item-0-6').val().length;
		counter -= newlines;
		$('#tx_mailform_label_textarea').text('('+ counter +' tekens over)');
		if ( counter < 0 ) {
			if ( ! $('#tx_mailform_label_textarea').hasClass('error') ) {
				$('#tx_mailform_label_textarea').addClass('error');
			}
			$('#tx_mailform_input-item-0-6').val($('#tx_mailform_input-item-0-6').val().substring(0, ( maxLength - newlines ) ) );
			$('#tx_mailform_label_textarea').text('(0 tekens over)');
		} else {
			if ( $('#tx_mailform_label_textarea').hasClass('error') ) {
				$('#tx_mailform_label_textarea').removeClass('error');	
			}
		}
	});

	
	
	/* 
		go-to-homepage fix
	*/
	
	$("ul li a.kwc-homepage").attr("href", "http://www.remeha.nl/");
	
	//rotate on/off
	var timeout_time=16000;
	if ( $('#rotate').html() == '1' ){ timeout_time=0; }
	
	$("#banners .banners").cycle({
		
		pager: '.banners-nav',
		speed:    400, 
   	    timeout:  timeout_time, 
    	pagerAnchorBuilder: function(idx, slide) { 
			// return selector string for existing anchor 
			return '.banners-nav li:eq(' + idx + ') a'; 
		} 
		
	});
	
	/*
	 	Flash animation
	 */
	
	if ( $('#flash').html() == null ){
		$('#showerlady').hide();
 	}else {
 		var so = new SWFObject('templates/consumenten-site/assets/images/swf/silhoutte/RandomMovieLoader.swf','player','250','181','9');
		so.addParam('allowscriptaccess','always');
		so.addParam('allowfullscreen','true');
		so.addParam('wmode','transparent');
		so.write('showerlady');
	}

	
	/*
	 	Anchor 
	 */
	
	$("#anchor a, #anchor_sitemap a").click(
	function ()
		{
			$(window).scrollTop(0);
			return false;
		}
	);
	
	/* 
		slide down, answer by FAQ page and technische begrippen.
	*/
	
	
	$(".faq-question h4, .term h4").click(
		
		function ()
		{	
		
			if($(this).parent().hasClass("selected"))//&& $(this).hasClass("selected")
			{
				
				$(this).parent().removeClass("selected").children("p").hide();
			
				wc('item closed');
				
			}
			else
			{
			
				$(this).parent().addClass("selected").children("p").show();
				
				wc('item open');
				
			}
		}
	
	);
	
	var selected = null;
	
	$("p.show-hide-toggle a").click(
		
		function ()
		{	
		
			if(selected !== true)
			{
				selected = true;
				
				$(this).html('Verberg alles');
			
				$(".item").addClass("selected").children("p").show();
				
				wc('alles open');

			}
			else
			{
			
				selected = false;
				
				$(this).html('Toon alles');
		
				$(".item").removeClass("selected").children("p").hide();
				
				wc('alles dicht');
				
			}
		}
	
	);

	/*
	|----------------------
	|Toggle table and info
	|---------------------
	*/
	 $('a#technical_link').click(function() {
			$('#info').hide('fast');
			$('#technical_table').show('fast');
			return false;
	 });
 
	 $('a#info_link').click(function() {
			$('#technical_table').hide('fast');
			$('#info').show('fast');
			return false;
	 });
	 
	 $('a#brochure_link').click(function() {
			$('#info').hide('fast');
			$('#brochure_frame').show('fast');
			return false;
	 });
	  $('a#info_brochurelink').click(function() {
			$('#brochure_frame').hide('fast');
			$('#info').show('fast');
			return false;
	 });
		
	/*
	| --------------------------------------------------------------------------------------------
	| Remeha ketels
	| --------------------------------------------------------------------------------------------
	*/
	
	
	var mycarousel_itemList = $("#product-selector ul li");
	
	
	if($('#product-selector').length)
	{
		$('#product-selector').jcarousel(
		{
			wrap: 'circular',
			
			animation: 'slow',
			
			buttonNextHTML: '<a class="prev-next-button next">&rsaquo;</a>', 
			buttonPrevHTML: '<a class="prev-next-button prev">&lsaquo;</a>',
			
			initCallback: mycarousel_initCallback,
			
			itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
		   
		   foo: 'bar'
		
		});
	
	}
	
	function mycarousel_initCallback(carousel, state) {
	
		if (state == 'init')
		{
			wc('Carousel initialised');
			
			/* 
				timer
			*/
			var t = 8000;
			
			var timer = $.timer(t, function (_t) {
				
				carousel.next();
				
				_t.reset(t);
				
			});
					
			$(carousel.container).hover(
			
				function()
				{
					wc('over');
					
					timer.stop();
				}, 
				function()
				{		
					wc('out');
					
					timer.reset(t);
				}
			);
			
		}
		else if (state == 'reset')
		{
			wc('Carousel reseted');
		}
	};
	
	function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
	{
		wc('mycarousel_itemVisibleInCallback');
		
		// The index() method calculates the index from a
		// given index who is out of the actual item range.
		var idx = carousel.index(i, mycarousel_itemList.length);
		
		var item = mycarousel_getItemHTML(mycarousel_itemList[idx - 1]);
	
		
		/* 
			add
		*/
		makeItemHooverable(
		
			carousel.add(i, item)
			
		);		
		
		$('ul.jcarousel-list').css({ 'width': '1600px' });
		
	};
	
	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
	{
			
		carousel.remove(i);
		
		$('ul.jcarousel-list').css({ 'width': '1600px' });
	};
	
	/**
	 * Item html creation helper.
	 */
	function mycarousel_getItemHTML(item)
	{

		return $(item).html();
	};

	function makeItemHooverable(item)
	{		
		item.hover(
		
			function()
			{
	
				$(this).stop().animate({
					
						width: "260px"
				
					}).children().children('.media').stop().animate({left: "100px"});
					
				
				$(this).children().children('.tooltip').css({"display":"block"});
				
				
			}, 
			function()
			{		
			
				$(this).stop().animate({
					
					width: "155px"
				
				}).children().children('.media').stop().animate({	left: "0px"	});
				
				
				$(this).children().children('.tooltip').hide();	
				
			}	
		);
		
	}
				
	
	/*
	| --------------------------------------------------------------------------------------------
	| Search veld
	| --------------------------------------------------------------------------------------------
	*/
	
	$("input.default-value").activeSearch();
	
});



/*
| --------------------------------------------------------------------------------------------
| Input value, switch
| --------------------------------------------------------------------------------------------
*/

$.fn.activeSearch = function(options) {
	
	var defaults = {
	
		active_color: '#000',// Colour of user provided text
		inactive_color: '#ccc'// Colour of default text
		
	}
	
	// Extend our default options with those provided.
	var opts = $.extend(defaults, options);
	
	// Our plugin implementation code goes here.
	return this.each(function() {

    	$(this).css("color", opts.inactive_color);
    	
  		var default_values = new Array();
		
		$(this).focus(function() 
		{
		
			if (!default_values[this.id]) 
			{
				default_values[this.id] = this.value;
			}
			
			if (this.value == default_values[this.id]) 
			{
			  this.value = '';
			  this.style.color = opts.active_color;
			}
			
			$(this).blur(function() 
			{
				if (this.value == '') 
				{
					this.style.color = opts.inactive_color;
					this.value = default_values[this.id];
				}
			
			});
			
  		});

  });
  
};

