// PRODUCT WRAPIN PLUGIN (INDEX)
(function($){
 $.fn.wrapChildren = function(options){

  var options = $.extend({ childElem: undefined, sets:1, wrapper:'div' }, options || {});
  if (options.childElem === undefined) return this;

  return this.each(function(){
   var elems = $(this).children(options.childElem);
   var arr = [];
    elems.each(function(i,value){
     arr.push(value);
     if (((i + 1) % options.sets === 0) || (i === elems.length -1)){ var set = $(arr); arr = []; set.wrapAll($("<" + options.wrapper + ">")); }
    });

  });

 }
})(jQuery);

// TIPS
(function($) {
	$.fn.easyTooltip = function(options){
		// default configuration properties
		var defaults = {	
			xOffset: 10,		
			yOffset: 25,
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",
			useElement: ""
		};
		var options = $.extend(defaults, options);  
		var content;
		this.each(function() {  				
			var title = $(this).attr("title");				
			$(this).hover(function(e){											 							   
				content = (options.content != "") ? options.content : title;
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
				$(this).attr("title","");									  				
				if (content != "" && content != undefined){			
					$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");		
					$("#" + options.tooltipId)
						.css("position","absolute")
						.css("top",(e.pageY - options.yOffset) + "px")
						.css("left",(e.pageX + options.xOffset) + "px")						
						.css("display","none")
						.fadeIn("fast")
				}
			},
			function(){	
				$("#" + options.tooltipId).remove();
				$(this).attr("title",title);
			});	
			$(this).mousemove(function(e){
				$("#" + options.tooltipId)
					.css("top",(e.pageY - options.yOffset) + "px")
					.css("left",(e.pageX + options.xOffset) + "px")					
			});	
			if(options.clickRemove){
				$(this).mousedown(function(e){
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});				
			}
		});
	};
})(jQuery);

// INDEX CHECK
if( location.href.split('/').pop() === "index.cfm" || location.href.split('/').pop() === "" ){

  // PLAYER 
  var so = new SWFObject("player.swf", "main", "440", "300", "8", "#FFFFFF");
   so.addParam("allowFullScreen", "true");
   so.addVariable("playOnStart", "false");
   so.addVariable("controlsSideMargin", "20");
   so.addVariable("controlsDownMargin", "10");	
   so.addVariable("onStartShowControls", "false");
   so.addVariable("autoHideVideoControls", "true");	
   so.addVariable("MediaLink", "video/vrpromo.flv");
   so.addVariable("image", "images/video-start.jpg");
   so.addVariable("logo", "images/brand.png");
   so.addVariable("logoLink", "http://www.vanranzow.com");
   so.addVariable("logoTarget", "_blank");
   so.addVariable("share", "false");
   so.write("player");

  // PRODUCTS
  $('#products').wrapChildren({childElem:'a', sets:5}).cycle({fx:'scrollUp', sync:0, speed:700, timeout:5000});	 
}

 // NAV
 $('#nav a').each(function(){ if( $(this).attr('href') === window.location.href || $(this).attr('href') === location.href.split('/').pop() ) $(this).addClass('current'); });

$(function(){

 // TABS
 $("blockquote:not(:first)").hide();
 $(".blockquote:first").show();
 $(".tabs li > a").click(function(){		
   stringref = $(this).attr("href").split('#')[1];
   $('blockquote:not(#'+stringref+')').hide();
   $('blockquote#' + stringref).fadeIn(); 
   return false;
 }); 

 // TABS E-shop
  if( $("#stappen").length ) $('#stappen').tabs();
	
 $('#toStap-2').click(function(){
  $(this).parents('div').eq(1).triggerTab(2);
  return false;
 });

 $("a.tip").easyTooltip();

});
