$.fn.inputfields = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};


$(window).load(function() {

	//ThreeDots
	var the_obj = $('.newsintro').ThreeDots({
		max_rows: 3
	});	


	$('#slider').nivoSlider({
		effect:'sliceUpDown', //Specify sets like: sliceDown, sliceDownLeft, sliceUp, sliceUpLeft, sliceUpDown, sliceUpDownLeft, fold, fade, random
		slices:10,
		animSpeed:800, //Slide transition speed
		pauseTime:8000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
      controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});

	//init product slideshow
	$('#catImage').cycle({
		fx: 'fade',
		speed: 2500,
		pause: 1
	});
	
	
	//FORMS
 /*   
    $('input[type="text"]').addClass("idleField");
	$('input[type="text"]').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
        if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
    });
    $('input[type="text"]').blur(function() {
    	$(this).removeClass("focusField").addClass("idleField");
        if ($.trim(this.value == '')){
        	this.value = (this.defaultValue ? this.defaultValue : '');
    	}
    });
*/	

	$(".text").inputfields();
	$(".textarea").inputfields();



	//bxSlider
	var slider = $('#productSlider').bxSlider({
            mode: 'vertical',
            controls: false
        });

    $('.thumbs a').click(function(){
        var thumbIndex = $('.thumbs a').index(this);
        slider.goToSlide(thumbIndex);
        $('.thumbs a').removeClass('pager-active');
        $(this).addClass('pager-active');
        return false;
    });

    $('.thumbs a:first').addClass('pager-active');


    //Retailers
    $('.retailer-listbox h3').next('ul').hide();
    $('.retailer-listbox h3').click(function(){

        $(this).next('ul').slideToggle('fast');
        $(this).toggleClass('current');

    });

	$(".retailer-listbox a").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'height'		:	230,
		'width'	    	:	550,
		'autoDimensions':	false,
		'type'          :	'iframe',   
		'overlayShow'	:	false
	});


	$("a.thickboxInspiration").click(function() {

		//caption == the first span-child of element
		var caption = $(this).next("div.thickbox-description").get(0).innerHTML;

		//show thickbox
		tb_show(caption, this.href, null);
		return false;
	});

    // INSPIRATION
    $("a.fullscreen").hover(
      function () {
        $(this).addClass("hover");
      },
      function () {
        $(this).removeClass("hover");
      }
    );

});







