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

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

	/*
		Char count  
	*/

	
	if (jQuery('textarea.max500').length){
		var stdText = jQuery('textarea.max500').text();
		// append
		jQuery('textarea.max500').before('<div id="chars-left">(Nog 500 tekens over)</div>');
		
		var maxLength=500;
		var counter=500;
		
		jQuery('textarea.max500').live('keyup', function(){
			
			var breaks = jQuery('textarea.max500').val().split("\n").length;
			var newlines = breaks - 1;
			counter = maxLength - jQuery('textarea.max500').val().length;
			counter -= newlines;
			jQuery('#chars-left').text('(Nog '+ counter +' tekens over)');
			if ( counter < 0 ) {
				if ( ! jQuery('#chars-left').hasClass('error') ) {
					jQuery('#chars-left').addClass('error');
				}
				jQuery('textarea.max500').val(jQuery('textarea.max500').val().substring(0, ( maxLength - newlines ) ) );
				jQuery('#chars-left').text('(Nog 0 tekens over)');
			} else {
				if ( jQuery('#chars-left').hasClass('error') ) {
					jQuery('#chars-left').removeClass('error');	
				}
			}
		});
		
		jQuery('form').submit(function(){
			if ( counter < 0 ) {
				return false;
			}
		});

	}

	
	
	/* 
		go-to-homepage fix
	*/
	
	jQuery("ul li a.kwc-homepage").attr("href", "http://www.remeha.nl/");
	
	//rotate on/off
	var timeout_time=16000;
	if ( jQuery('#rotate').html() == '1' ){ timeout_time=0; }
	
	jQuery("#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'; 
		} 
		
	});
	
	
	/*
	 	Popup in iframe 
	 */
	
	jQuery("a.more_hre").click(
		function () 
		{
			
			var hre_title  = ".title-" + jQuery(this).attr('id');
			var hre_id  = "#hre" + jQuery(this).attr('id');
			popup_hre(jQuery(hre_title).html(), jQuery(hre_id).html());
			return false;
		}
	)
	
	/*
	 	Anchor 
	 */
	
	jQuery("#anchor a, #anchor_sitemap a").click(
	function ()
		{
			jQuery(window).scrollTop(0);
			return false;
		}
	);
	
	/* 
		slide down, answer by FAQ page
	*/
	
	
	jQuery(".faq-question h4, .term h4").click(
		
		function ()
		{	
			if(jQuery(this).parent().hasClass("selected"))
			{
				jQuery(this).parent().removeClass("selected").children("p").hide();
			}
			else
			{
				jQuery(this).parent().addClass("selected").children("p").show();
			}
		}
	
	);
	
	var selected = null;
	
	jQuery("p.show-hide-toggle a").click(
		
		function ()
		{	
			if(selected !== true)
			{
				selected = true;
				jQuery(this).html('Hide everything');
				jQuery(".item").addClass("selected").children("p").show();
			}
			else
			{
				selected = false;
				jQuery(this).html('Show all');
				jQuery(".item").removeClass("selected").children("p").hide();
				
			}
		}
	
	);

	/*
	|----------------------
	|Toggle table and info
	|---------------------
	*/
	 jQuery('a#technical_link').click(function() {
			jQuery('#info').hide('fast');
			jQuery('#technical_table').show('fast');
			return false;
	 });
 
	 jQuery('a#info_link').click(function() {
			jQuery('#technical_table').hide('fast');
			jQuery('#info').show('fast');
			return false;
	 });
	 
	 jQuery('a#brochure_link').click(function() {
			jQuery('#info').hide('fast');
			jQuery('#brochure_frame').show('fast');
			return false;
	 });
	  jQuery('a#info_brochurelink').click(function() {
			jQuery('#brochure_frame').hide('fast');
			jQuery('#info').show('fast');
			return false;
	 });
		
	/*
	| --------------------------------------------------------------------------------------------
	| Remeha kazan
	| --------------------------------------------------------------------------------------------
	*/
	
	
	var mycarousel_itemList = jQuery("#product-selector ul li");
	
	
	if(jQuery('#product-selector').length)
	{
		
		jQuery('span.tooltip,span.media,span.title').show();
		
		jQuery('#product-selector').jcarousel(
		{
			wrap: 'circular',		
			animation:0,
			auto: 0,	
			buttonNextHTML: null, 
			buttonPrevHTML: null,
			
			//initCallback: mycarousel_initCallback,
			
			itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
		   
		   foo: 'bar'
		
		});
	
	}
	
	function mycarousel_initCallback(carousel, state) {
	
	
	
		if (state == 'init')
		{
			/* 
				timer
			*/
			var t =8000;
			
			var timer = jQuery.timer(t, function (_t) {
				
				carousel.next();
				
				_t.reset(t);
				
			});
					
			jQuery(carousel.container).hover(
			
				function()
				{
					timer.stop();
				}, 
				function()
				{		
					timer.reset(t);
				}
			);
			
		}
		else if (state == 'reset')
		{
			//wc('Carousel reseted');
		}
	};
	
	function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
	{
		// 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)
			
		);		
		
		jQuery('ul.jcarousel-list').css({ 'width': '1600px' });
		
	};
	
	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
	{
			
		carousel.remove(i);
		
		jQuery('ul.jcarousel-list').css({ 'width': '1600px' });
	};
	
	/**
	 * Item html creation helper.
	 */
	function mycarousel_getItemHTML(item)
	{

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

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



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

jQuery.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 = jQuery.extend(defaults, options);
	
	// Our plugin implementation code goes here.
	return this.each(function() {

    	jQuery(this).css("color", opts.inactive_color);
    	
  		var default_values = new Array();
		
		jQuery(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;
			}
			
			jQuery(this).blur(function() 
			{
				if (this.value == '') 
				{
					this.style.color = opts.inactive_color;
					this.value = default_values[this.id];
				}
			
			});
			
  		});

  });
  
};


