$(function() {
      $("ul#nav li").each(function(){
		if ($(this).children('a').html().length > 20) {
			$(this).addClass('long');
		}
      });


		   
	$(".banner-bottom div").removeAttr("style");
	$(".banner-bottom .csc-textpic").removeAttr("class");

	// history template initilaze deafult text
	$(".box-text").html( $("#link-01").html() );	
	
	// history actions
	$(".history-link").click(function() {
		$(".box-text").css("display", "none");		
		$(".box-text").html($(this).html());
		$(".box-text").slideDown();	
	});

	$('.content img[style*=left]').addClass('img-left');
	$('.content img[style*=right]').addClass('img-right');
	
	$(".content ul").each(function() {
		$(this).find("li:last").addClass("border-none");
	});
	$(".content ol").each(function() {
		$(this).find("li:last").addClass("border-none");
	});
	
	// songs youtube actions
	$("#video-bar a").click(function() {
		var video_id = $(this).closest("li").attr("rel");
		$("#video-player").html( show_video(video_id, 399, 260) );
		return false;
	});
	$("#video-bar a:eq(0)").click();
	
	// hide li without rel attr
	$("#video-bar ul li").each(function () {
		if( !$(this).attr("rel") ) {
			$(this).hide();
		}
	});
	
	if($.browser.safari) {
		$("#nav li a").css('padding-top', '2px');
		$("#nav li a").css('padding-top', '2px');
	}

	$(".tx-macinasearchbox-pi1 input[name=tx_indexedsearch[sword]]").defaultVal();	
	$(".frm-signup input[name=name]").defaultVal();	
	$(".frm-signup input[name=email]").defaultVal();	
	$(".frm-signup input[name=telephone]").defaultVal();	
	$(".frm-signup input[name=sms]").defaultVal();	
	
	$('#slider').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		controlNav:true, //1,2,3...
		directionNav:false, //Next & Prev
		keyboardNav:true, //Use left & right arrows
		animSpeed:1000, //Slide transition speed
        pauseTime:5000		
	});
	
	$('.banner-big').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		controlNav:false, //1,2,3...
		directionNav:false, //Next & Prev
		directionNavHide:false, //Only show on hover
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		animSpeed:1000, //Slide transition speed
        pauseTime:5000		
	});
	
	$(".nivo-control:eq(0)").addClass("item-1");
	$(".nivo-control:eq(1)").addClass("item-2");
	$(".nivo-control:eq(2)").addClass("item-3");

	$("#nav > li, #nav-zeva > li").hover(										 
	   //function() { $(this).addClass("hover"); $(".dd").slideUp(50); $(this).children(".dd").slideDown(); }
	  //,function() { $(this).removeClass("hover"); $(this).children(".dd").slideUp(50); }
 	  function() { $(this).addClass("hover"); $(this).children(".dd").show(); }
	  ,function() { $(this).removeClass("hover"); $(this).children(".dd").hide(); }
	 );

	var n_visible = $('.carousel li').length;
	// fix if 0 > items
	if(n_visible > 0) {	
		// fix if 5 < items
		if(n_visible < 5) {
			$('.btn-prev').addClass('no-bg');
			$('.btn-next').addClass('no-bg');
			$('.carousel li').last().addClass('last');
			// fix align center
			n_center = ((5 - n_visible) / 2) * 174;
			$('.your-zewa-carousel').css('margin-left', n_center+'px');
			$('#close-your-zewa').css('margin', '4px 0 0 '+(n_center-6)+'px');
		} else {		
			$('#close-your-zewa').css('margin', '4px 0 0 -6px');
			var n_visible = 5;		
		}	
	
		// carousel
		$(".your-zewa-carousel").jCarouselLite({
			visible: n_visible,
			btnNext: ".btn-next",
			btnPrev: ".btn-prev"
		});	
	
		// fix border > 5 items
		if(n_visible >= 5){
			$(".dd-your-zewa .your-zewa-carousel").css("width",874);		
		}
		
		$(".your-zewa").hover(
			function () {
				$(".dd-your-zewa").css("top","29px");
				$("#your-zewa-left").css("display","block");
				$("#your-zewa-right").css("display","block");
			},
			function () {
				$(".dd-your-zewa").css("top","-300px");
				$("#your-zewa-left").css("display","none");
				$("#your-zewa-right").css("display","none")
			}
		);
		$("#close-your-zewa").click(
			function () {
				$(".dd-your-zewa").css("top","-300px");
				$("#your-zewa-left").css("display","none");
				$("#your-zewa-right").css("display","none")	
			}
		);
	} else {
		$(".your-zewa a").css("cursor", "default");
	}	
	
	$(".banner-list").jCarouselLite({
        visible: 1,
		btnNext: ".btn-next",
    	btnPrev: ".btn-prev"
    });
	
	$(".size-item").mouseover(
		function () {
			$(".sizes li a").removeClass("hover");
			$(this).addClass("hover");
			$("#product-img").attr('src',$(this).attr('rel'));
		}
	);	

	/*
	// found default product image
	img_big_src = $("#product-img").attr('src');
	if(img_big_src) {
		img_big_pos = img_big_src.indexOf(".jpg");
		img_big_src = img_big_src.substring(0, img_big_pos);
		//alert(img_big_src);
		// mark sizes rule rel
		$(".sizes ul li a").each(function () {
			// remove _XX.jpg from rel
			img_rel_src = $(this).attr("rel") ;
			img_rel_pos = img_rel_src.indexOf(".jpg");
			img_rel_src = img_rel_src.substring(0, img_rel_pos - 3);	
			if( img_rel_src == img_big_src ) {
				$(this).addClass("hover");
			}
		});
	}*/

	$(".product-overview .nav a").mouseover(
		function () {
			$(this).parent().parent().parent().find(".product-overview-img-4columns img").attr('src',$(this).attr('rel'));
			$(this).parent().parent().parent().find(".product-overview-img-5columns img").attr('src',$(this).attr('rel'));
		}
	);
	
});


function show_video(video_id, width, height) {
	var url = "http://www.youtube.com/v/"+video_id;
	return '<object width="'+width+'" height="'+height+'"><param name="wmode" value="transparent"> <param name="movie" value="'+url+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+url+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="'+width+'" height="'+height+'"></embed></object>'; 
} //end show()	


// slide with fade
$.fn.slideFadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
};


/* ------------------------------------------------------------------------------------------------------------------------------------
/* !===> Div Links */
/* ------------------------------------------------------------------------------------------------------------------------------------
 * Div link - searches the element for anchor tags and adds the first one as the click action
 * ------------------------------------------------------------------------------------------------------------------------------------ */
(function ($) {
 $.fn.divlink = function(params) {
  // Default options
  var params = jQuery.extend({
    
  }, params);
  
  $(this).each(function() {
   var $first_link = $(this).find("a");
   
   $(this).data('first_link', $first_link.attr("href"));
   $(this).click(function() {
	//console.log($(this).data('first_link'));						  
    document.location = $first_link.attr("href");
   });
   $(this).css("cursor", "pointer");
   $(this).hover(
     function() { $(this).addClass("hover"); }
    ,function() { $(this).removeClass("hover"); }
   );
  }); //end each()
  
 }; //end function()
})(jQuery);


/* ------------------------------------------------------------------------------------------------------------------------------------
/* !===> Default Input Value */
/* ------------------------------------------------------------------------------------------------------------------------------------ */
(function ($) {
 $.fn.defaultVal = function(params) {
  // Default options
  var params = jQuery.extend({
    defaultOverride: false
  }, params);
  
  $(this).each(function() {
   var $el = $(this);
   
   // Remember the default value
   if (params.defaultOverride) $el.data('default_value', params.defaultOverride);
   else       $el.data('default_value', $el.val());
   
   // Focus and blur actions
   $el.focus(function() {
    $el.addClass('focus');
    if ( ! $el.data('not_default')) {
     $el.data('not_default', 1);
     $el.val('');
    } //end if
   }).blur(function() {
    if ( ! $el.val()) {
     if ($el.data('default_value')) $el.val( $el.data('default_value') );
     $el.data('not_default', 0);
    } //end if
   });
   
  }); //end each()
 }; //end function()
})(jQuery);

/* ZewaKids Downloadlinks
------------------------------------------------------------------------------*/
$(document).ready(function(){
	$('.zewaKids_funzone_animal .item').click(function(){
		window.open('/' + $(this).find('a').attr('href'), '_blank');
		return false;	
	});
});

/* Zewa Winterspecial 2011
------------------------------------------------------------------------------*/

//getURL( "javascript:openItem(" + _root.action + ", " + _root.param + ");" );
	function openItem(action, param) {
		window.open('/' + param);		
		//console.log(action);
		//console.log(param);
	} 
	
/* Zewa Winterspecial 2011
------------------------------------------------------------------------------*/
$(document).ready(function() {
	   $('.txt1').hide();
	   $('.txt2').hide();
	   $('.txt3').hide();
	   $('.txt4').hide();
	   $('.txt5').hide();

    $('.btn1').hover(
        function() { $('.txt1').stop(true, true).fadeIn(); },
        function() { $('.txt1').stop(true, true).fadeOut(); } 
    );
	
	$('.btn2').hover(
        function() { $('.txt2').stop(true, true).fadeIn(); },
        function() { $('.txt2').stop(true, true).fadeOut(); }
    );
	
	$('.btn3').hover(
        function() { $('.txt3').stop(true, true).fadeIn(); },
        function() { $('.txt3').stop(true, true).fadeOut(); }
    );	
	
	$('.btn4').hover(
        function() { $('.txt4').stop(true, true).fadeIn(); },
        function() { $('.txt4').stop(true, true).fadeOut(); }
    );
		
	$('.btn5').hover(
        function() { $('.txt5').stop(true, true).fadeIn(); },
        function() { $('.txt5').stop(true, true).fadeOut(); }
	);
	
});	
	
