function init_slider() {
	var zoom_slider_array = $A(document.getElementsByClassName('slider'));
	zoom_slider_array.each( function(s, index) {
		jQuery(s).easySlider({
			
			nextId: "slidernext" + index,
			prevId: "sliderprev" + index
		});
	});
};

function init_tabs() {
  jQuery("ul.tabs").tabs("div.panes > div.panes_element"); 
};

function init_accordion() {
  jQuery(".accordion h2:first").addClass("active");
	jQuery(".accordion .accordion_element:not(:first)").hide();

	jQuery(".accordion h2").click(function(){
		jQuery(this).next(".accordion_element").slideToggle("slow")
		.siblings(".accordion_element:visible").slideUp("slow");
		jQuery(this).toggleClass("active");
		jQuery(this).siblings("h2").removeClass("active");
	});
}




function add_to_product_compare_list(product_id, category_id){
if(jQuery('#'+product_id).is(':checked')){
			var dataString = 'product_id='+ product_id + '&category_id=' + category_id + '&action=add&timeis=' + (Math.random()*100000);
			jQuery('#'+product_id).hide(); //show loading	
			jQuery('#load_'+product_id).show(); //show checkbox
			jQuery.ajax({
				type: 'GET',
				url: '/ajax/compare_products.php',
				dataType: 'xml',
				data: dataString,		
				 success: function(data){
												
						 jQuery(data).find('product').each(function(){
							 jQuery('#'+jQuery(this).text()).attr('checked', false); //unchecks others, that are out of three element array
						 });
						 jQuery('#load_'+product_id).hide(); //hide loading	
						 jQuery('#'+product_id).show(); //show checkbox
					  }	
																		
			});
			
	}else{
		jQuery('#'+product_id).hide();
		 jQuery('#load_'+product_id).show();
		var dataString = 'product_id='+ product_id + '&category_id=' + category_id + '&action=remove&timeis=' + (Math.random()*100000);
			jQuery.ajax({
				type: 'GET',
				url: '/ajax/compare_products.php',
				data: dataString,
				dataType: 'xml',
					 success: function(data){
						 jQuery('#load_'+product_id).hide(); //hide loading	
						 jQuery('#'+product_id).show(); //show checkbox
					  }	
				 												
			});
		
			
			
	//category_id, product_id
	//alert(category_id+' '+pro

	}
}



function save_hk(){

	// finds the referrer
	var referrer = 0;
	if(document.referrer == null){ referrer = 0; } else { var referrer = document.referrer; }
	

	// function to get hostneme
	function get_hostname(url) {
		var m = ((url||'')+'').match(/^http:\/\/[^/]+/);
		return m ? m[0].substring(7) : null; //cuts off http://
		
	}
	
	//function to get elements from referrer and send to php
	function get_elements(referrer){
		if(referrer == 0) {
			var hostname = 'not set';
		}
		else {	
			var hostname = get_hostname(referrer);
		}
		
	//finds if exists in referrer at all
		if(hostname != null){			
			var is_search_engine = false; // variable to save bool value if known search engine has detected
			var search_engine_variable_letter = null; // variable to save SE specified letter in refferer to save keywords
			
			if(hostname.toLowerCase().search( 'google' )>= 0){ // checks if SE is google
				
				is_search_engine = true;
				search_engine_variable_letter = 'q';		
			} else if (hostname.toLowerCase().search( 'yahoo' )>= 0){ 
				is_search_engine = true;
				search_engine_variable_letter = 'p';		
			} else if (hostname.toLowerCase().search( 'bing' )>= 0){
				is_search_engine = true;
				search_engine_variable_letter = 'q';
			} else if (hostname.toLowerCase().search( 'ask' )>= 0){
				is_search_engine = true;
				search_engine_variable_letter = 'q';
				//aol
			} else if (hostname.toLowerCase().search( 'aol' )>= 0){
				is_search_engine = true;
				search_engine_variable_letter = 'q';
			} else if ( referrer.toLowerCase().search( 'q=' ) >=0){
				is_search_engine = true;
				search_engine_variable_letter = 'q';
			} else if ( referrer.toLowerCase().search( 'p=' ) >=0){
				is_search_engine = true;
				search_engine_variable_letter = 'p';
			}
			
								   
					
		
			if(is_search_engine){ //cheks if search engine is detected
			  
				var str1 = '?'+search_engine_variable_letter+'='; //?x=
				var str2 = '&'+search_engine_variable_letter+'='; //&x=
			  
				var sub_str = ''; //stores substring
					if(referrer.indexOf(str1) != -1){ //see if keywords are after ?x=
						sub_str = referrer.substring(referrer.indexOf(str1)); //cuts off all before ?x=
						
					} else if (referrer.indexOf(str2) != -1){ //see if keywords are after &x=
						sub_str = referrer.substring(referrer.indexOf(str2)); //cuts off all before &x=
					}
					  sub_str = sub_str.substring(3); //cuts off ?x= or &x=
					
					if(sub_str.indexOf('&') != -1) { //checks if there is another & symbol after keywords
					
					  sub_str = sub_str.substring(sub_str.indexOf(sub_str), sub_str.indexOf('&')); //cuts of all the rest behind & symbol (including)
					}
					
					//finds again if referrer contains ?x= or &x=
					if (referrer.indexOf(str1) != -1 || referrer.indexOf(str2) != -1){
					   
						var sub_str_decoded = decodeURIComponent(sub_str).replace(/\+/g, ' '); //decodes string, removes plus symbol
						sub_str_decoded = sub_str_decoded.replace(/\+/g, '%20'); // removes whitespaces
						
					// finds if there are some keywords	
						if(sub_str_decoded){ 
							
							var dataString = 'hostname='+ hostname + '&keywords=' + sub_str_decoded;
							
							jQuery.ajax({
								type: 'GET',
								url: 'http://de.y-o-w.com/js_scripts/save_hostname_keywords.php',
								data: dataString
																						
							});
						}
					}
					
				
			}
		}
	}
	get_elements(referrer);
}

//easyslider
(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 		'',
			nextId: 		'nextBtn',	
			nextText: 		'',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			800,
			auto:			false,
			pause:			2000,
			continuous:		false, 
			numeric: 		false,
			numericId: 		'controls'
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			var clickable = true;
			obj.width(w); 
			obj.height(h); 
			obj.css("overflow","hidden");
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);			
			
			if(options.continuous){
				$("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px"));
				$("ul", obj).append($("ul li:nth-child(2)", obj).clone());
				$("ul", obj).css('width',(s+1)*w);
			};				
			
			if(!options.vertical) $("li", obj).css('float','left');
								
			if(options.controlsShow){
				var html = options.controlsBefore;				
				if(options.numeric){
					html += '<ol id="'+ options.numericId +'"></ol>';
				} else {
					//if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
					//html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
					//html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
					//if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';				
				};
				
				html += options.controlsAfter;						
				$(obj).after(html);										
			};
			
			if(options.numeric){									
				for(var i=0;i<s;i++){						
					$(document.createElement("li"))
						.attr('id',options.numericId + (i+1))
						.html('<a rel='+ i +' href=\"javascript:void(0);\">'+ (i+1) +'</a>')
						.appendTo($("#"+ options.numericId))
						.click(function(){							
							animate($("a",$(this)).attr('rel'),true);
						}); 												
				};							
			} else {
				$("a","#"+options.nextId).click(function(){		
					animate("next",true);
				});
				$("a","#"+options.prevId).click(function(){		
					animate("prev",true);				
				});	
				$("a","#"+options.firstId).click(function(){		
					animate("first",true);
				});				
				$("a","#"+options.lastId).click(function(){		
					animate("last",true);				
				});				
			};
			
			function setCurrent(i){
				i = parseInt(i)+1;
				alert(options.numericId);
				$("li", "#" + options.numericId).removeClass("current");
				$("li#" + options.numericId + i).addClass("current");
			};
			
			function adjust(){
				if(t>ts) t=0;		
				if(t<0) t=ts;	
				if(!options.vertical) {
					$("ul",obj).css("margin-left",(t*w*-1));
				} else {
					$("ul",obj).css("margin-left",(t*h*-1));
				}
				clickable = true;
				if(options.numeric) setCurrent(t);
			};
			
			function animate(dir,clicked){
				if (clickable){
					clickable = false;
					var ot = t;				
					switch(dir){
						case "next":
							t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;						
							break; 
						case "prev":
							t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
							break; 
						case "first":
							t = 0;
							break; 
						case "last":
							t = ts;
							break; 
						default:
							t = dir;
							break; 
					};	
					var diff = Math.abs(ot-t);
					var speed = diff*options.speed;						
					if(!options.vertical) {
						p = (t*w*-1);
						$("ul",obj).animate(
							{ marginLeft: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);				
					} else {
						p = (t*h*-1);
						$("ul",obj).animate(
							{ marginTop: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);					
					};
					
					if(!options.continuous && options.controlsFade){					
						if(t==ts){
							$("a","#"+options.nextId).hide();
							$("a","#"+options.lastId).hide();
						} else {
							$("a","#"+options.nextId).show();
							$("a","#"+options.lastId).show();					
						};
						if(t==0){
							$("a","#"+options.prevId).hide();
							$("a","#"+options.firstId).hide();
						} else {
							$("a","#"+options.prevId).show();
							$("a","#"+options.firstId).show();
						};					
					};				
					
					if(clicked) clearTimeout(timeout);
					if(options.auto && dir=="next" && !clicked){;
						timeout = setTimeout(function(){
							animate("next",false);
						},diff*options.speed+options.pause);
					};
			
				};
				
			};
			// init
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};		
			
			if(options.numeric) setCurrent(0);
		
			if(!options.continuous && options.controlsFade){					
				$("a","#"+options.prevId).hide();
				$("a","#"+options.firstId).hide();				
			};				
			
		});
	  
	};

})(jQuery);

//Tabs
(function($) {
		
	// static constructs
	$.tools = $.tools || {};
	
	$.tools.tabs = {
		version: '1.0.4',
		
		conf: {
			tabs: 'a',
			current: 'current',
			onBeforeClick: null,
			onClick: null, 
			effect: 'default',
			initialIndex: 0,			
			event: 'click',
			api:false,
			rotate: false
		},
		
		addEffect: function(name, fn) {
			effects[name] = fn;
		}
	};		
	
	
	var effects = {
		
		// simple "toggle" effect
		'default': function(i, done) { 
			this.getPanes().hide().eq(i).show();
			done.call();
		}, 
		
		/*
			configuration:
				- fadeOutSpeed (positive value does "crossfading")
				- fadeInSpeed
		*/
		fade: function(i, done) {
			var conf = this.getConf(), 
				 speed = conf.fadeOutSpeed,
				 panes = this.getPanes();
			
			if (speed) {
				panes.fadeOut(speed);	
			} else {
				panes.hide();	
			}

			panes.eq(i).fadeIn(conf.fadeInSpeed, done);	
		},
		
		// for basic accordions
		slide: function(i, done) {			
			this.getPanes().slideUp(200);
			this.getPanes().eq(i).slideDown(400, done);			 
		}, 

		// simple AJAX effect
		ajax: function(i, done)  {			
			this.getPanes().eq(0).load(this.getTabs().eq(i).attr("href"), done);	
		}
		
	};   	
	
	var w;
	
	// this is how you add effects
	$.tools.tabs.addEffect("horizontal", function(i, done) {
	
		// store original width of a pane into memory
		if (!w) { w = this.getPanes().eq(0).width(); }
		
		// set current pane's width to zero
		this.getCurrentPane().animate({width: 0}, function() { $(this).hide(); });
		
		// grow opened pane to it's original width
		this.getPanes().eq(i).animate({width: w}, function() { 
			$(this).show();
			done.call();
		});
		
	});	
	 

	function Tabs(tabs, panes, conf) { 
		
		var self = this, $self = $(this), current;

		// bind all callbacks from configuration
		$.each(conf, function(name, fn) {
			if ($.isFunction(fn)) { $self.bind(name, fn); }
		});
		
		
		// public methods
		$.extend(this, {				
			click: function(i, e) {
				
				var pane = self.getCurrentPane();				
				var tab = tabs.eq(i);												 
				
				if (typeof i == 'string' && i.replace("#", "")) {
					tab = tabs.filter("[href*=" + i.replace("#", "") + "]");
					i = Math.max(tabs.index(tab), 0);
				}
								
				if (conf.rotate) {
					var last = tabs.length -1; 
					if (i < 0) { return self.click(last, e); }
					if (i > last) { return self.click(0, e); }						
				}
				
				if (!tab.length) { 
					if (current >= 0) { return self; }
					i = conf.initialIndex;
					tab = tabs.eq(i);
				}				
				
				// current tab is being clicked
				if (i === current) { return self; }
				
				// possibility to cancel click action				
				e = e || $.Event();
				e.type = "onBeforeClick";
				$self.trigger(e, [i]);				
				if (e.isDefaultPrevented()) { return; }
				
				// call the effect
				effects[conf.effect].call(self, i, function() {

					// onClick callback
					e.type = "onClick";
					$self.trigger(e, [i]);					
				});			
				
				// onStart
				e.type = "onStart";
				$self.trigger(e, [i]);				
				if (e.isDefaultPrevented()) { return; } 
				
				// default behaviour
				current = i;
				tabs.removeClass(conf.current);	
				tab.addClass(conf.current);

				return self;
			},
			
			getConf: function() {
				return conf;	
			},

			getTabs: function() {
				return tabs;	
			},
			
			getPanes: function() {
				return panes;	
			},
			
			getCurrentPane: function() {
				return panes.eq(current);	
			},
			
			getCurrentTab: function() {
				return tabs.eq(current);	
			},
			
			getIndex: function() {
				return current;	
			}, 
			
			next: function() {
				return self.click(current + 1);
			},
			
			prev: function() {
				return self.click(current - 1);	
			}, 
			
			bind: function(name, fn) {
				$self.bind(name, fn);
				return self;	
			},	
			
			onBeforeClick: function(fn) {
				return this.bind("onBeforeClick", fn);
			},
			
			onClick: function(fn) {
				return this.bind("onClick", fn);
			},
			
			unbind: function(name) {
				$self.unbind(name);
				return self;	
			}			
		
		});
		
		
		// setup click actions for each tab
		tabs.each(function(i) { 
			$(this).bind(conf.event, function(e) {
				self.click(i, e);
				return false;
			});			
		});

		// if no pane is visible --> click on the first tab
		if (location.hash) {
			self.click(location.hash);
		} else {
			if (conf.initialIndex === 0 || conf.initialIndex > 0) {
				self.click(conf.initialIndex);
			}
		}		
		
		// cross tab anchor link
		panes.find("a[href^=#]").click(function(e) {
			self.click($(this).attr("href"), e);		
		}); 
	}
	
	
	// jQuery plugin implementation
	$.fn.tabs = function(query, conf) {
		
		// return existing instance
		var el = this.eq(typeof conf == 'number' ? conf : 0).data("tabs");
		if (el) { return el; }

		if ($.isFunction(conf)) {
			conf = {onBeforeClick: conf};
		}
		
		// setup options
		var globals = $.extend({}, $.tools.tabs.conf), len = this.length;
		conf = $.extend(globals, conf);		

		
		// install tabs for each items in jQuery		
		this.each(function(i) {				
			var root = $(this); 
			
			// find tabs
			var els = root.find(conf.tabs);
			
			if (!els.length) {
				els = root.children();	
			}
			
			// find panes
			var panes = query.jquery ? query : root.children(query);
			
			if (!panes.length) {
				panes = len == 1 ? $(query) : root.parent().find(query);
			}			
			
			el = new Tabs(els, panes, conf);
			root.data("tabs", el);
			
		});		
		
		return conf.api ? el: this;		
	};		
		
}) (jQuery); 

