(function($){ 
	
	$.fn.selBox = function(options){
		
		var opts = $.extend({}, $.fn.selBox.defaults, options);
		
		return this.each(function(){
			
			var sBox  = this;
			var $sBox = $(this);
			
			var o = $.meta ? $.extend({}, opts, $sBox.data()) : opts;
			
			var hasFocus     = 0;
			var hasScroll    = 0;
			var layerHeight  = 0;
			var hoveredIndex = 0;
			
			var $container;
			var $input;
			var $layer;
			var $options;
			var $selectedOpt;
			var $hoveredOpt;
			
			sBox.init = function(){
				$container = sBox.buildContainer();
				$input = sBox.buildInput();
				$layer = sBox.buildLayer();
				
				$input.width((($sBox.innerWidth() > o.maxInputWidth) ? o.maxInputWidth : $sBox.innerWidth()) - o.arrowWidth);
				$container.width(($sBox.innerWidth() > o.maxInputWidth) ? o.maxInputWidth : $sBox.innerWidth());
				
				$container.append($input).append($layer);
				
				$sBox.hide().before($container);
				
				$layer.width((($sBox.innerWidth() > o.maxInputWidth) ? o.maxInputWidth : $sBox.innerWidth()) - 2).css("top", o.selectHeight + 1);
				if ($layer.height() > o.maxHeight) {
					hasScroll = 1;
					$layer.height(o.maxHeight);
				}
				layerHeight = $layer.height();
				
				$options = $("li", $layer);
				$selectedOpt = $options.filter("." + o.optOnClass);
				$hoveredOpt = $options.filter("." + o.optHoverClass);
				
				sBox.assignActions();
			}
			
			sBox.buildContainer = function(){
				return $("<div id=\"" + $sBox.attr("id") + "_sBox\" class=\"" + o.containerClass + "\"></div>");
			}
			
			sBox.buildInput = function(){
				return $("<input type=\"text\" id=\"" + $sBox.attr("id") + "_sBoxInput\" class=\"" + o.inputClass + "\" tabIndex=\"" + $sBox.attr("tabindex") + "\" autocomplete=\"off\" readonly=\"readonly\" style=\"-moz-user-select: none;\" />");
			}
			
			sBox.buildLayer = function(){
				var _opt = "<ul id=\"" + $sBox.attr("id") + "_sBoxOptions\" class=\"" + o.layerClass + "\">";
				
				$("option", sBox).each(function(i, v){
					var $v = $(v);
					var _class = "";
					
					if ($v.is(":selected")) {
						_class = " class=\"" + o.optOnClass + " " + o.optHoverClass + "\"";
						$input.val($v.text());
						hoveredIndex = i;
					}
					
					_opt += "<li" + _class + " rel=\"" + $v.val() + "\">" + $v.html() + "</li>";
				});
				
				_opt += "</ul>";
				
				return $(_opt);
			}
			
			sBox.assignActions = function(){
				
				$container.click(function(e){
					$input.click().get(0).focus();
					e.preventDefault(); e.stopPropagation();
				}).hover(function(e){
					hasFocus = 1;
				}, function(e){
					hasFocus = 0;
				});
				
				$layer.hover(function(){}, function(){
					hasFocus = 0;
				})
				
				$input.focus(function(e){
					e.preventDefault(); e.stopPropagation();
				}).blur(function(e){
					if (hasFocus == 0) {
						$layer.hide();
					}
					e.preventDefault(); e.stopPropagation();
				}).keydown(function(e){
					sBox.inputKey(e.keyCode);
					e.preventDefault(); e.stopPropagation();
				}).click(function(e){
					sBox.toggleLayer();
					e.preventDefault(); e.stopPropagation();
				});
				
				$options.click(function(e){
					$input.get(0).focus();
					sBox.optionChange($(this));
					e.preventDefault(); e.stopPropagation();
				}).mouseover(function(e){
					sBox.hoverChange($(this));
					e.preventDefault(); e.stopPropagation();
				});
			}
			
			sBox.toggleLayer = function(){
				$layer.toggle();
				if ($layer.is(":visible")) {
					hasFocus = 1;
					sBox.scrollTo($selectedOpt);
				}
			}
			
			sBox.scrollTo = function($obj){
				if (hasScroll > 0) {
					var optionOffset = $obj.get(0).offsetTop;
					var layerOffset = $layer.get(0).scrollTop;
					
					if (optionOffset < layerOffset) {
						$layer.scrollTop(optionOffset);
					}
					else if ((optionOffset - layerHeight) >= layerOffset) {
						$layer.scrollTop(optionOffset - layerHeight + $obj.height() + 2);
					}
				}
			}
			
			sBox.inputKey = function(key){
				
				switch(key) {
					case 33: // pgUp
						sBox.moveKey(-10);
						break;
					case 34: // pgDown
						sBox.moveKey(10);
						break;
					case 38: // up
						sBox.moveKey(-1);
						break;
					case 40: // down
						sBox.moveKey(1);
						break;
					case 36: // home
						sBox.moveKey(0);
						break;
					case 35: // end
						sBox.moveKey($options.length - 1);
						break;
					case 13: // return
						if ($layer.is(":visible")) {
							sBox.optionChange($hoveredOpt);
						}
						else {
							$layer.show();
							sBox.scrollTo($selectedOpt);
						}
						break;
					case 27: // escape
						$layer.hide();
						break;
						
					default:
						if ((key >= 48 && key <= 57) || (key >= 65 && key <= 90) || (key >= 97 && key <= 122)) {
						
							var patt = new RegExp("^" + String.fromCharCode(key), "i");
							var hasFirst = 0;
							
							$newOpt = $options.filter(function(i){
								if (!hasFirst && (patt.test($options[i].innerHTML) == true)) {
									hasFirst = 1;
									return true;
								}
								else if ((i > hoveredIndex) && (patt.test($options[i].innerHTML) == true)) {
									return true;
								}
								else {
									return false;
								}
							});
							
							if ($newOpt.length > 0) {
								
								if ($newOpt.length > 1) {
									newSel = 1;
								}
								else {
									newSel = 0
								}
								
								if ($layer.is(":visible")) {
									sBox.scrollTo($($newOpt.get(newSel)));
									sBox.hoverChange($($newOpt.get(newSel)));
								}
								else {
									sBox.optionChange($($newOpt.get(newSel)));
								}
							}
						}
				}
			}
			
			sBox.optionChange = function($obj){
				$input.val($obj.text());
				
				$("option", sBox).removeAttr("selected").filter("[value='" + $obj.attr("rel") + "']").attr("selected", "selected");
				
				$layer.hide();
				$selectedOpt.removeClass(o.optOnClass);
				$obj.addClass(o.optOnClass);
				$selectedOpt = $obj;
				sBox.hoverChange($obj);
				
				o.afterChange.call(this, $obj);
			}
			
			sBox.hoverChange = function($obj){
				$hoveredOpt.removeClass(o.optHoverClass);
				$obj.addClass(o.optHoverClass);
				$hoveredOpt = $obj;
				hasFocus = 1;
				hoveredIndex = $options.index($obj);
			}
			
			sBox.moveKey = function(offset){
				if ($layer.is(":visible")) {
					var _index = $options.index($hoveredOpt);
					var _new_index;
					
					if ((offset == 0) || (offset == ($options.length - 1))) {
						_new_index = offset;
					}
					else {
						_new_index = ((_index + offset) < 0) ? 0 : (((_index + offset) > ($options.length - 1)) ? ($options.length - 1) : (_index + offset));
					}
					
					sBox.hoverChange($($options[_new_index]));
					sBox.scrollTo($($options[_new_index]));
				}
				else {
					var _index = $options.index($selectedOpt);
					var _new_index
					
					if ((offset == 0) || (offset == ($options.length - 1))) {
						_new_index = offset;
					}
					else {
						_new_index = ((_index + offset) < 0) ? 0 : (((_index + offset) > ($options.length - 1)) ? ($options.length - 1) : (_index + offset));
					}
					
					sBox.optionChange($($options[_new_index]));
				}
			}
			
			sBox.init();
			
		});
	};
	
	$.fn.selBox.defaults = {
		maxHeight      : 240,
		maxInputWidth  : 220,
		arrowWidth     : 25,
		selectHeight   : 20,
		containerClass : "sBox_container",
		inputClass     : "sBox_input",
		layerClass     : "sBox_layer",
		optOnClass     : "sBox_optOn",
		optHoverClass  : "sBox_optHover",
		afterChange    : function(obj){}
	};
	
})(jQuery);  
;// General products functions #################################################################
$(function(){
	// Assign sort select actions
	$("select#order_by").selBox({afterChange: function(obj){
		$("#sort_form").find("input:hidden[name='__s']").val($(obj).attr("rel")).end().submit();
	}});

	// Assign actions for left column filters
	assign_filters_actions();

	// Add report links
	$("span.report_container").each(function(i, v){
		$(this).html("<a href=\"" + PATH_SELF + "\" class=\"dark smaller\" onclick=\"view_iframe('" + do_link("site.report_problem", "pp=up&section=shopping&p=" + $(this).metadata().prod_key) + "', '" + LANG_TXT_REPORT_ERROR + "', 750, 550); return false;\">" + LANG_TXT_REPORT_ERROR + "</a>");
	})

	// Toggle magnify overlay
	$(".col_img").hover(function(e){
		$(".magnify", this).show();
	}, function(e){
		$(".magnify", this).hide();
	});
	
	$("dd.invisible:first").height(Math.min(155, $("dd.invisible:first").height())).removeClass("invisible");

	// Toggle recomended stores
	var clicked_stores = $.cookie("_ckst_");
	$(".feat_store").each(function(i, v){
		var m_data = $(this).metadata();
		
		if (clicked_stores != null) {
			if ($.inArray(m_data.store_key, clicked_stores.split("|")) && (m_data.allow == "on")) {
				$("#recc_store_container_" + m_data.store_key).hide();
			}
			else {
				$("#recc_store_container_" + m_data.store_key).show();
			}
		}
	});
});

// Animate product image
function animate_prod_img(row_element, destination){
	// Show animation only if toolbar is visible
	if ($("#user_toolbar").width() > 100) {
		// Clone product image and begin animation
		var img = $(row_element).closest("li").find("img[id^='pic_']:first");
		if (img.length) {
			var new_img = img.clone();
			new_img.css({position: 'absolute', zIndex: '1000', top: img.offset().top + 'px', left: img.offset().left + 'px'}).appendTo("body").animate({opacity: 0.5, width: '15px', height: '15px', top: $(destination).offset().top + 5, left: ($(destination).offset().left + $(destination).width() - 15)}, 1000, 'easeOutBounce', function(){$(this).remove()});
		}
	}
}

// Wishlist functions #################################################################

// Add single wishlist link or confirmation message
function add_wishlist_link(key, disabled){
	// Add confirmation message
	if (disabled) {
		$("#prod_row_" + key + " .wishlist_link").html("<a href=\"" + PATH_SELF + "\" class=\"i_fav_saved request_fav_prod_delete {page: 'my.remote', request: 'fav_prod_delete', p: '" + key + "', container: '#prod_row_" + key + " .wishlist_link', datatype: 'script', post: {_RETURN: '" + RETURN + "'}}\">&nbsp;</a>");
	}
	// Add save to wishlist link
	else {
		$("#prod_row_" + key + " .wishlist_link").html("<a href=\"" + PATH_SELF + "\" class=\"i_fav_save request_fav_prod_add {page: 'my.remote', request: 'fav_prod_add', p: '" + key + "', container: '#prod_row_" + key + " .wishlist_link', datatype: 'script', post: {_RETURN: '" + RETURN + "'}}\" title=\"" + LANG_TXT_SAVE_LIST + "\">&nbsp;</a>");
	}
}

// Get products from wishlist
function populate_wishlist_links(data){
	// Build array with product keys
	prod_keys = $(data.keys.split(","));
	// Loop product rows and add links or messages
	$("li[id^='prod_row_']").each(function(i, v){
		var key = $(v).attr("id").substr(9);
		add_wishlist_link(key, ($.inArray(key, prod_keys) != -1) );
	});
	// Assign live actions for save links
	$("a.request_fav_prod_add").live("click", function(){
		// Animate product image
		if (USR_profile_key > 0) {
			animate_prod_img($(this), "#fav_ajax_tab");
		}
		// Send save request and refresh layer
		do_remote_action($.extend($(this).metadata(), {callback: function(data){
			refresh_fav_layer("prod");
		}}));
		
		return false;
	});
	// Assign live actions for remove links
	$("a.request_fav_prod_delete").live("click", function(){
		// Send save request and refresh layer
		do_remote_action($.extend($(this).metadata(), {callback: function(data){
			refresh_fav_layer("prod");
		}}));
		
		return false;
	});
}

// Callback after single product delete
function after_fav_prod_delete(data){
	add_wishlist_link(data.p, 0);
}

// Callback after multiple product delete
function after_fav_prod_delete_list(data){
	$("li[id^='prod_row_']").each(function(i, v){
		add_wishlist_link($(v).attr("id").substr(9), 0);
	});
}

// Compare functions #################################################################

// Build compare links
function add_top_links(nr_prod, cat) {
	
	if (typeof(cat) == "undefined") {cat = 0;}
	nr_prod = parseInt(nr_prod);
	
	// If cat was specified, check to match current cat
	if ( (cat == 0) || (cat == THIS_CAT_cat_key) ) {
		// Replace counter
		var prod_txt = LANG_TXT_COUNT_COMPARE_PRODUCTS.replace("#1", nr_prod);
		var compare_link = "";
		// Build counter text and compare link
		if (nr_prod > 1) {
			compare_link = "<a href=\"" + do_link("site.compare", "online=" + THIS_CAT_cat_str_key + "&type=saved") + "\" class=\"i_compare\" rel=\"nofollow\" target=\"_blank\" title=\"" + LANG_TXT_COMPARE_PROD + "\">&nbsp;</a> " + 
			"<a href=\"" + do_link("site.compare", "online=" + THIS_CAT_cat_str_key + "&type=saved") + "\" class=\"gray smaller bg_yel\" rel=\"nofollow\" target=\"_blank\">" + LANG_TXT_COMPARE_PROD + "</a> ";
		}
		else {
			compare_link = "<span class=\"gray smaller\">" + LANG_TXT_COMPARE_ALERT + "</span> ";
		}
		
		if (nr_prod > 0) {
			compare_link += "<span class=\"gray smaller\">(" + prod_txt + ")</span>";
		}
		// Add counters to page
		$("#compare_link_row").html(compare_link);
		$("#compare_link_row_btm").html(compare_link);
	}
}

// Get products from compare list
function populate_compare_checks(options){

	// All checkboxes from compare form
	var cks = $("input:checkbox", "#compare_form");
	// Refresh counters
	add_top_links(comps['c' + THIS_CAT_cat_key]);
	
	// We have products for current category
	if (comps['c' + THIS_CAT_cat_key] > 0) {
		// Build array width product keys
		prod_keys = $(options.keys.split(","));
		// Check selected checkboxes
		prod_keys.each(function(i){
			cks.filter("[value='" + this + "']").attr("checked", "checked");
		});
	}
	// Enable checkboxes
	cks.removeAttr("disabled");
	// Assign checkbox actions
	cks.click(function(e){
		var jThis = $(this);
		// If is checked
		if (jThis.is(":checked")) {
			// Animate product image
			animate_prod_img(jThis, "#comp_ajax_tab");
			// Send save request
			$.get(do_link("site.remote", "request=comp_prod_add&p=" + jThis.val()), function(data){
				// Update counters
				add_top_links(comps['c' + THIS_CAT_cat_key], THIS_CAT_cat_key);
				// Refresh layer
				refresh_comp_layer();
			}, "script");
		}
		else {
			// Send delete request
			$.get(do_link("site.remote", "request=comp_prod_delete&p=" + jThis.val()), function(data){
				// Update counters
				add_top_links(comps['c' + THIS_CAT_cat_key], THIS_CAT_cat_key);
				// Refresh layer
				refresh_comp_layer();
			}, "script");
		}
	});
}

// Callback after single product delete
function after_comp_prod_delete(data){
	// Refresh counters
	add_top_links(comps['c' + data.c], data.c);
	// Select checkboxes
	$("#prod_row_" + data.p + " .col_check :checkbox").removeAttr("checked");
}

// Callback after multiple product delete
function after_comp_prod_delete_list(data){
	// Refresh counters
	add_top_links(0, data.c);
	// If current cat was deleted, uncheck all product checkboxes
	if ($("#compare_form").metadata().c == data.c) {
		$("#compare_form input:checkbox").removeAttr("checked");
	}
}
;;(function ($) {
    $.fn.carousel = function (params) {
        var params = $.extend({
            direction: "horizontal",
            loop: false,
            dispItems: 1,
            pagination: false,
            paginationPosition: "inside",
            nextBtn: '<a role="button">&nbsp;</a>',
            prevBtn: '<a role="button">&nbsp;</a>',
            btnsPosition: "inside",
            nextBtnInsert: "appendTo",
            prevBtnInsert: "prependTo",
            nextBtnInsertFn: false,
            prevBtnInsertFn: false,
            autoSlide: false,
            autoSlideInterval: 3000,
            delayAutoSlide: false,
            combinedClasses: false,
            effect: "slide",
            slideEasing: "swing",
            animSpeed: "normal",
            equalWidths: "true",
            verticalMargin: 0,
            callback: function () {},
            useAddress: false,
            adressIdentifier: "carousel",
            tabLabel: function (tabNum) {
                return tabNum;
            }
        }, params);
        if (params.btnsPosition == "outside") {
            params.prevBtnInsert = "insertBefore";
            params.nextBtnInsert = "insertAfter";
        }
        params.delayAutoSlide = params.delayAutoSlide || params.autoSlideInterval;
        return this.each(function () {
            var env = {
                $elts: {},
                params: params,
                launchOnLoad: []
            };
	    
	    var uls = $(this).children();
	    var lis = uls.find("li");
	    if (env.params.loop && (lis.length % env.params.dispItems) && (lis.length > env.params.dispItems)) {
		for (var i=0; i<(env.params.dispItems - (lis.length % env.params.dispItems)); i++) {
			cln = $(lis[i]).clone();
			cln.appendTo(uls);
		}
	    }
	    
            env.$elts.carousel = $(this).addClass("js");
            env.$elts.content = $(this).children().css({
                position: "absolute",
                "top": 0
            });
            env.$elts.wrap = env.$elts.content.wrap('<div class="carousel-wrap"></div>').parent().css({
                overflow: "hidden",
                position: "relative"
            });
            env.steps = {
                first: 0,
                count: env.$elts.content.children().length
            };
            env.steps.last = env.steps.count - 1;
            if ($.isFunction(env.params.prevBtnInsertFn)) {
                env.$elts.prevBtn = env.params.prevBtnInsertFn(env.$elts);
            } else {
                env.$elts.prevBtn = $(params.prevBtn)[params.prevBtnInsert](env.$elts.carousel);
            }
            if ($.isFunction(env.params.nextBtnInsertFn)) {
                env.$elts.nextBtn = env.params.nextBtnInsertFn(env.$elts);
            } else {
                env.$elts.nextBtn = $(params.nextBtn)[params.nextBtnInsert](env.$elts.carousel);
            }
            env.$elts.nextBtn.addClass("carousel-control next carousel-next");
            env.$elts.prevBtn.addClass("carousel-control previous carousel-previous");
	    $(this).siblings(".carousel_nav_sep").remove();
            initButtonsEvents(env);
            if (env.params.pagination) {
                initPagination(env);
            }
            initAddress(env);
            $(function () {
                var $items = env.$elts.content.children();
                var $maxHeight = 0;
                $items.each(function () {
                    $item = $(this);
                    $itemHeight = $item.outerHeight();
                    if ($itemHeight > $maxHeight) {
                        $maxHeight = $itemHeight;
                    }
                });
                if (env.params.verticalMargin > 0) {
                    $maxHeight = $maxHeight + env.params.verticalMargin;
                }
                $items.height($maxHeight);
                var $firstItem = env.$elts.content.children(":first");
                env.itemWidth = $firstItem.outerWidth();
                if (params.direction == "vertical") {
                    env.contentWidth = env.itemWidth;
                } else {
                    if (params.equalWidths) {
                        env.contentWidth = env.itemWidth * env.steps.count;
                    } else {
                        env.contentWidth = (function () {
                            var totalWidth = 0;
                            env.$elts.content.children().each(function () {
                                totalWidth += $(this).outerWidth();
                            });
                            return totalWidth;
                        })();
                    }
                }
                env.$elts.content.width(env.contentWidth);
                env.itemHeight = $maxHeight;
                if (params.direction == "vertical") {
                    env.$elts.content.css({
                        height: env.itemHeight * env.steps.count + "px"
                    });
                    env.$elts.content.parent().css({
                        height: env.itemHeight * env.params.dispItems + "px"
                    });
                } else {
                    env.$elts.content.parent().css({
                        width: env.itemWidth * env.params.dispItems + "px",
                        height: env.itemHeight + "px"
                    });
                }
                updateButtonsState(env);
                $.each(env.launchOnLoad, function (i, fn) {
                    fn();
                });
                if (env.params.autoSlide) {
                    window.setTimeout(function () {
                        resetSliderInterval(env);
                    }, env.params.delayAutoSlide);
                }
		
		env.params.callback(0);
            });
        });
    };
    
    function resetSliderInterval(env) {
	stopAutoSlide(env);
	env.autoSlideInterval = window.setInterval(function () {
	    goToStep(env, getRelativeStep(env, "next"));
	}, env.params.autoSlideInterval);
    }

    function initButtonsEvents(env) {
        env.$elts.nextBtn.add(env.$elts.prevBtn).bind("enable", function () {
            var $this = $(this).unbind("mousedown").bind("mousedown", function () {
                goToStep(env, getRelativeStep(env, ($this.is(".next") ? "next" : "prev")));
		if (env.params.autoSlide) {
			resetSliderInterval(env);
		}
            }).removeClass("disabled");
            if (env.params.combinedClasses) {
                $this.removeClass("next-disabled previous-disabled");
            }
        }).bind("disable", function () {
            var $this = $(this).unbind("mousedown").addClass("disabled");
            if (env.params.combinedClasses) {
                if ($this.is(".next")) {
                    $this.addClass("next-disabled");
                } else if ($this.is(".previous")) {
                    $this.addClass("previous-disabled");
                }
            }
        }).hover(function () {
            $(this).toggleClass("hover");
        });
    };

    function initPagination(env) {
        env.$elts.pagination = $('<div class="center-wrap"><div class="carousel-pagination"><p></p></div></div>')[((env.params.paginationPosition == "outside") ? "insertAfter" : "appendTo")](env.$elts.carousel).find("p");
        env.$elts.paginationBtns = $([]);
        env.$elts.content.find("li").each(function (i) {
            if (i % env.params.dispItems == 0) {
                env.$elts.paginationBtns = env.$elts.paginationBtns.add($('<a role="button"><span>' + env.params.tabLabel(env.$elts.paginationBtns.length + 1) + '</span></a>').data("firstStep", i));
            }
        });
        env.$elts.paginationBtns.each(function () {
            $(this).appendTo(env.$elts.pagination);
        });
        env.$elts.paginationBtns.slice(0, 1).addClass("active");
        env.launchOnLoad.push(function () {
            env.$elts.paginationBtns.click(function (e) {
                goToStep(env, $(this).data("firstStep"));
                stopAutoSlide(env);
            });
        });
    };

    function initAddress(env) {
        if (env.params.useAddress && $.isFunction($.fn.address)) {
            $.address.init(function (e) {
                var pathNames = $.address.pathNames();
                if (pathNames[0] === env.params.adressIdentifier && !! pathNames[1]) {
                    goToStep(env, pathNames[1] - 1);
                } else {
                    $.address.value('/' + env.params.adressIdentifier + '/1');
                }
            }).change(function (e) {
                var pathNames = $.address.pathNames();
                if (pathNames[0] === env.params.adressIdentifier && !! pathNames[1]) {
                    goToStep(env, pathNames[1] - 1);
                }
            });
        } else {
            env.params.useAddress = false;
        }
    };

    function goToStep(env, step) {
        env.params.callback(step);
        transition(env, step);
        env.steps.first = step;
        updateButtonsState(env);
        if (env.params.useAddress) {
            $.address.value('/' + env.params.adressIdentifier + '/' + (step + 1));
        }
    };

    function getRelativeStep(env, position) {
        if (position == "prev") {
            if ((env.steps.first - env.params.dispItems) >= 0) {
                return env.steps.first - env.params.dispItems;
            } else {
                return ((env.params.loop) ? (env.steps.count - env.params.dispItems) : false);
            }
        } else if (position == "next") {
            if ((env.steps.first + env.params.dispItems) < env.steps.count) {
                return env.steps.first + env.params.dispItems;
            } else {
                return ((env.params.loop) ? 0 : false);
            }
        }
    };

    function transition(env, step) {
        switch (env.params.effect) {
        case "no":
            if (env.params.direction == "vertical") {
                env.$elts.content.css("top", -(env.itemHeight * step) + "px");
            } else {
                env.$elts.content.css("left", -(env.itemWidth * step) + "px");
            }
            break;
        case "fade":
            if (env.params.direction == "vertical") {
                env.$elts.content.hide().css("top", -(env.itemHeight * step) + "px").fadeIn(env.params.animSpeed);
            } else {
                env.$elts.content.hide().css("left", -(env.itemWidth * step) + "px").fadeIn(env.params.animSpeed);
            }
            break;
        default:
            if (env.params.direction == "vertical") {
                env.$elts.content.stop().animate({
                    top: -(env.itemHeight * step) + "px"
                }, env.params.animSpeed, env.params.slideEasing);
            } else {
                env.$elts.content.stop().animate({
                    left: -(env.itemWidth * step) + "px"
                }, env.params.animSpeed, env.params.slideEasing);
            }
            break;
        }
    };

    function updateButtonsState(env) {
        if (getRelativeStep(env, "prev") !== false) {
            env.$elts.prevBtn.trigger("enable");
        } else {
            env.$elts.prevBtn.trigger("disable");
        }
        if (getRelativeStep(env, "next") !== false) {
            env.$elts.nextBtn.trigger("enable");
        } else {
            env.$elts.nextBtn.trigger("disable");
        }
        if (env.params.pagination) {
            env.$elts.paginationBtns.removeClass("active").filter(function () {
                return ($(this).data("firstStep") == env.steps.first)
            }).addClass("active");
        }
    };

    function stopAutoSlide(env) {
        if ( !! env.autoSlideInterval) {
            window.clearInterval(env.autoSlideInterval);
        }
    };
})(jQuery);
;function google_ad_request_done(google_ads){
	
	var boxAds_1 = "";
	var boxAds_2 = "";
	var boxAds_3 = "";
	var ads_div_1_parts = new Array(2);
	var ads_div_2_parts = new Array(2);
	var ads_div_3_parts = new Array(2);
	var i;
	var rows_separator;
	
	// Divs we use to display data
	if ((typeof(AFC_content_div_1) != "undefined") && AFC_content_div_1 != "") {
		ads_div_1_parts = AFC_content_div_1.split(":", 2);
	}
	if ((typeof(AFC_content_div_2) != "undefined") && AFC_content_div_2 != "") {
		ads_div_2_parts = AFC_content_div_2.split(":", 2);
	}
	
	if ((typeof(AFC_content_div_3) != "undefined") && AFC_content_div_3 != "") {
		ads_div_3_parts = AFC_content_div_3.split(":", 2);
	}
	
	// Default number of ads for each separate type
	if (!ads_div_1_parts[1]) {ads_div_1_parts[1] = 99;}
	if (!ads_div_2_parts[1]) {ads_div_2_parts[1] = 99;}
	if (!ads_div_3_parts[1]) {ads_div_3_parts[1] = 99;}
	/*
	* Verify that there are actually ads to display.
	*/
	if (google_ads.length <= 0) {
		return;
	}
	
	/*
	* If an image or flash ad is returned, display that ad.
	* Otherwise, build a string containing all of the ads and
	* then use a document.write() command to print that string.
	*/
	
	if (google_ads[0].type == "flash") {
		boxAds_1 += '<a href="' + 
		google_info.feedback_url + '" target="_blank" class="small dark" style="color:000000">' + AFC_txt_ads_by_google + '</a><br />' + 
		'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
		' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="' + 
		google_ad.image_width + '" HEIGHT="' + 
		google_ad.image_height + '"> <PARAM NAME="movie" VALUE="' + 
		google_ad.image_url + '">' + 
		'<PARAM NAME="quality" VALUE="high">' + 
		'<PARAM NAME="AllowScriptAccess" VALUE="never">' + 
		'<EMBED src="' + 
		google_ad.image_url + '" WIDTH="' + 
		google_ad.image_width + '" HEIGHT="' + 
		google_ad.image_height + 
		'" TYPE="application/x-shockwave-flash"' + 
		' AllowScriptAccess="never" ' + 
		' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
	}
	else if (google_ads[0].type == "image") {
		boxAds_1 += '<a href="' + 
		google_info.feedback_url + '" target="_blank" class="small dark" style="color:000000">' + AFC_txt_ads_by_google + '</a><br /> <a href="' + 
		google_ads[0].url + '" target="_blank" title="go to ' + 
		google_ads[0].visible_url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
		google_ads[0].visible_url + '\';return true"><img border="0" src="' + 
		google_ads[0].image_url + '"width="' + 
		google_ads[0].image_width + '"height="' + 
		google_ads[0].image_height + '"></a>';
	}
	else if (google_ads[0].type == "html") {
		boxAds_1 += google_ads[0].snippet;
	}
	else {
		if (google_ads.length == 1) {
			/*
			* Partners should adjust text sizes
			* so ads occupy the majority of ad space.
			*/
			
			boxAds_1 += '<a href="' + 
			google_info.feedback_url + '" target="_blank" class="small dark" style="color:000000">' + AFC_txt_ads_by_google + '</a><br /> <a style="text-decoration:none" href="' + 
			google_ads[0].url + '" target="_blank" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
			google_ads[0].visible_url + '\';return true"> <span class="' + AFC_font_class + ' bold" style="text-decoration:underline;"> <b>' + 
			google_ads[0].line1 + '</b><br /></span></a> <span class="' + AFC_font_class + ' dark">' +
			google_ads[0].line2 + '&nbsp;' +
			google_ads[0].line3 + '<br /></span> <span class="' + AFC_font_class + '"><a style="color:#CC0000;text-decoration:none" href="' + 
			google_ads[0].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
			google_ads[0].visible_url + '\';return true">' + 
			google_ads[0].visible_url + '</span></a><br />';
		}
		else if (google_ads.length > 1) {
			
			if (AFC_ad_rows == 2) {rows_separator = "<br />";}
			else {rows_separator = " ";}
			
			boxAds_1 += '<a href="' + google_info.feedback_url + '" target="_blank" class="small dark" style="color:000000">' + AFC_txt_ads_by_google + '</a><br />';
			boxAds_2 += '<a href="' + google_info.feedback_url + '" target="_blank" class="small dark" style="color:000000">' + AFC_txt_ads_by_google + '</a><br />';
			// boxAds_3 += '<a href="' + google_info.feedback_url + '" target="_blank" class="small dark" style="color:000000">' + AFC_txt_ads_by_google + '</a><br />';
			/*
			 * For text ads, append each ad to the string.
			 */
			
			for(i = 0; i < google_ads.length; ++i) {
				if (i < parseInt(ads_div_1_parts[1])) {
					boxAds_1 += get_ads_row(google_ads[i], rows_separator, AFC_font_class);
				}
				else if (i < (parseInt(ads_div_1_parts[1]) + parseInt(ads_div_2_parts[1]))) {
					boxAds_2 += get_ads_row(google_ads[i], rows_separator, AFC_font_class);
				}
				else if (i < (parseInt(ads_div_1_parts[1]) + parseInt(ads_div_2_parts[1]) + parseInt(ads_div_3_parts[1]))) {
					boxAds_3 += get_ads_row(google_ads[i], rows_separator, AFC_font_class);
				}
			}
		}
	}
	
	// Assing HTML
	if ((typeof(ads_div_1_parts[0]) != "undefined") && ads_div_1_parts[0] != "") {
		document.getElementById(ads_div_1_parts[0]).innerHTML = boxAds_1;
	}	
	if ((typeof(ads_div_2_parts[0]) != "undefined") && ads_div_2_parts[0] != "") {
		document.getElementById(ads_div_2_parts[0]).innerHTML = boxAds_2;
	}
	if ((typeof(ads_div_3_parts[0]) != "undefined") && ads_div_3_parts[0] != "") {
		document.getElementById(ads_div_3_parts[0]).innerHTML = boxAds_3;
	}
	
	return;
}

function get_ads_row(data, rows_separator, font){
	
	var row;
	
	if (font == "bold") {
		row = "<div class=\"cfix dark small ads_hover_row\" style=\"margin-top: 0.75em;\">" + 
			"<a style=\"font-weight: 700; font-size: 15px; text-decoration: underline;\" href=\"" + data.url + "\"" +
			" target=\"_blank\" onmouseout=\"window.status=''\" onmouseover=\"window.status='go to " + data.visible_url + "';return true;\">" +
			data.line1 + "</a><br />" +
			"<a style=\"color: #CC0000; text-decoration: none;\" href=\"" + data.url + "\"" +
			" target=\"_blank\" onmouseout=\"window.status=''\" onmouseover=\"window.status='go to " + data.visible_url + "';return true;\">" +
			data.visible_url + "</a> " +
			data.line2 + rows_separator +
			((typeof(data.line3) != "undefined") ? data.line3 : "") +
		"</div>";
	}
	else {
		row = "<div class=\"cfix dark small ads_hover_row\" style=\"margin-top: 0.75em;\">" + 
			"<a style=\"font-weight: 700; text-decoration: underline;\" href=\"" + data.url + "\"" +
			" target=\"_blank\" onmouseout=\"window.status=''\" onmouseover=\"window.status='go to " + data.visible_url + "';return true;\">" +
			data.line1 + "</a><br />" +
			data.line2 + rows_separator +
			((typeof(data.line3) != "undefined") ? data.line3 : "") + "<br />" +
			"<a style=\"color: #CC0000; text-decoration: none;\" href=\"" + data.url + "\"" +
			" target=\"_blank\" onmouseout=\"window.status=''\" onmouseover=\"window.status='go to " + data.visible_url + "';return true;\">" +
			data.visible_url + "</a>" +
		"</div>";
	}
	
	return row;
}

function google_afs_request_done(google_ads){

	var boxAds_1 = "";
	var boxAds_2 = "";
	var boxAds_3 = "";
	var ads_div_1_parts = new Array(2);
	var ads_div_2_parts = new Array(2);
	var ads_div_3_parts = new Array(2);
	
	// Divs we use to display data
	if ((typeof(AFS_content_div_1) != "undefined") && AFS_content_div_1 != "") {
		ads_div_1_parts = AFS_content_div_1.split(":", 2);
	}
	if ((typeof(AFS_content_div_2) != "undefined") && AFS_content_div_2 != "") {
		ads_div_2_parts = AFS_content_div_2.split(":", 2);
	}
	if ((typeof(AFS_content_div_3) != "undefined") && AFS_content_div_3 != "") {
		ads_div_3_parts = AFS_content_div_3.split(":", 2);
	}
	
	if (google_ads.length <= 0) {
		return;
	}

	for(i = 0; i < google_ads.length; i++) {
		if (google_ads[i].type == "text/wide") {		
			if (i < parseInt(ads_div_1_parts[1])) {
				boxAds_1 += get_ads_row(google_ads[i], "", AFS_font_class);
			}
			else if (i < (parseInt(ads_div_1_parts[1]) + parseInt(ads_div_2_parts[1]))) {
				boxAds_2 += get_ads_row(google_ads[i], "", AFS_font_class);
			}
			else if (i < (parseInt(ads_div_1_parts[1]) + parseInt(ads_div_2_parts[1]) + parseInt(ads_div_3_parts[1]))) {
				boxAds_3 += get_ads_row(google_ads[i], "", AFS_font_class);
			}
		}
	}

	if (boxAds_1 != "") {
		boxAds_1 = '<a style="text-decoration:none" ' +
		'href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation" target="_blank">' +
		'<span class="dark small brd_dot" style="text-align:left">' + AFS_txt_ads_by_google + '</span><br /></a>' + boxAds_1;
	}
	if (boxAds_2 != "") {
		boxAds_2 = '<a style="text-decoration:none" ' +
		'href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation" target="_blank">' +
		'<span class="dark small brd_dot" style="text-align:left">' + AFS_txt_ads_by_google + '</span><br /></a>' + boxAds_2;
	}
	if (boxAds_3 != "") {
		boxAds_3 = '<a style="text-decoration:none" ' +
		'href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation" target="_blank">' +
		'<span class="dark small brd_dot" style="text-align:left">' + AFS_txt_ads_by_google + '</span><br /></a>' + boxAds_3;
	}

	// Assing HTML
	if ((typeof(ads_div_1_parts[0]) != "undefined") && ads_div_1_parts[0] != "") {
		document.getElementById(ads_div_1_parts[0]).innerHTML = boxAds_1;
	}
	if ((typeof(ads_div_2_parts[0]) != "undefined") && ads_div_2_parts[0] != "") {
		document.getElementById(ads_div_2_parts[0]).innerHTML = boxAds_2;
	}
	if ((typeof(ads_div_3_parts[0]) != "undefined") && ads_div_3_parts[0] != "") {
		document.getElementById(ads_div_3_parts[0]).innerHTML = boxAds_3;
	}
	
	return;
}