// Populate country select #######################################################
// form_id, select_id_countries, select_id_states, select_id_cities, selected_country
function populate_countries(opt, callback){
	
	// Find selects in my form
	var countries_select = $("#" + opt.select_id_countries , "form#" + opt.form_id);
	var states_select = $("#" + opt.select_id_states, "form#" + opt.form_id);
	var cities_select = $("#" + opt.select_id_cities, "form#" + opt.form_id);
	
	// Empty + disable + add one option with loading text
	countries_select.empty().attr("disabled", "disabled").append("<option value=\"0\">" + txt_loading + "</option>");
	states_select.empty().attr("disabled", "disabled").append("<option value=\"0\">" + txt_loading + "</option>");
	cities_select.empty().attr("disabled", "disabled").append("<option value=\"0\">" + txt_loading + "</option>");
	
	// Change selected country key into a number
	opt.selected_country = parseInt(opt.selected_country);
	
	// Build request link
	var URL = do_link("site.remote", "request=select_countries");
	// Load data from remote
	countries_select.load(URL, {}, function(){
		// Enable countries select
		countries_select.removeAttr("disabled");
		
		// We have a selected country to set
		if (opt.selected_country > 0) {
			countries_select.setOption(opt.selected_country);
		}
		
		// We have a callback function to call
		if (typeof(callback) == "function") {
			countries_select.unbind("change").change(function(e){
				callback.call();
			}).change();
		}
	});
}

// Populate states select #######################################################
// form_id, select_id_countries, select_id_states, select_id_cities, selected_state
function populate_states(opt, callback){
	
	// Find selects in my form
	var countries_select = $("#" + opt.select_id_countries , "form#" + opt.form_id);
	var states_select = $("#" + opt.select_id_states, "form#" + opt.form_id);
	var cities_select = $("#" + opt.select_id_cities, "form#" + opt.form_id);
	
	// Empty + disable + add one option with loading text
	states_select.empty().attr("disabled", "disabled").append("<option value=\"0\">" + txt_loading + "</option>");
	cities_select.empty().attr("disabled", "disabled").append("<option value=\"0\">" + txt_loading + "</option>");
	
	// Get selected country
	country_selection = (opt.country_key > 0 ? opt.country_key : parseInt(countries_select.getOption()));
	// Change selected state key into a number
	opt.selected_state = parseInt(opt.selected_state);
	
	// We need the country
	if (country_selection > 0) {
		// Build request link
		var URL = do_link("site.remote", "request=select_states&fk_countries=" + country_selection);
		// Load data from remote
		states_select.load(URL, {}, function(){
			// Enable states select
			states_select.removeAttr("disabled");
			
			// We have a selected state to set
			if (opt.selected_state > 0) {
				// alert(states_select.find("option").length);
				states_select.setOption(opt.selected_state);
			}
			
			// We have a callback function to call
			if (typeof(callback) == "function") {
				states_select.unbind("change").change(function(e){
					callback.call();
				}).change();
			}
		});
	}
}

// Populate cities select #######################################################
// form_id, select_id_states, select_id_cities, selected_city
function populate_cities(opt, callback){
	
	// Find selects in my form
	var states_select = $("#" + opt.select_id_states, "form#" + opt.form_id);
	var cities_select = $("#" + opt.select_id_cities, "form#" + opt.form_id);
	
	// Empty + disable + add one option with loading text
	cities_select.empty().attr("disabled", "disabled").append("<option value=\"0\">" + txt_loading + "</option>");
	
	// Get selected state
	state_selection = parseInt(states_select.getOption());
	// Change selected city key into a number
	opt.selected_city = parseInt(opt.selected_city);
	
	// We need the state
	if (state_selection > 0) {
		// Build request link
		var URL = do_link("site.remote", "request=select_cities&fk_states=" + state_selection);
		// Load data from remote
		cities_select.load(URL, {}, function(){
			// Enable cities select
			cities_select.removeAttr("disabled");
			
			// We have a selected city to set
			if (opt.selected_city > 0) {
				cities_select.setOption(opt.selected_city);
			}
			
			// We have a callback function to call
			if (typeof(callback) == "function") {
				callback.call();
			}
		});
	}
}

// Populate zones select #######################################################

function populate_zones(form_id, select_name_cities, select_name_zones, selected_zone){
		
	var zones_select = jQuery("form#" + form_id + " select[name='" + select_name_zones + "']");
	
	// cities_select.empty().addOption("0", txt_loading + "...").attr("disabled", "disabled");
	zones_select.empty();
	jQuery("<option value=\"" + 0 + "\"></option>").html(txt_loading + "...").appendTo(zones_select);
	zones_select.attr("disabled", "disabled");
	
	var city_select = $("form#" + form_id + " select[name='" + select_name_cities + "']");
	
	var cities_selection = city_select.selectedValues()[0];
	
	if (cities_selection > 0) {
	
		var URL = do_link("site.remote", "request=select_zones&fk_cities=" + cities_selection);
		
		zones_select.load(URL, {}, function(){
		
			zones_select.removeAttr("disabled");
			
			if ((selected_zone != undefined) && (selected_zone != "") && (selected_zone != 0)) {
				// jQuery(zones_select).find("option[value='" + selected_zone + "']").attr("selected", "selected");
				zones_select.selectOptions(selected_zone, true);
			}
			else {
				// jQuery(cities_select).find("option[value='0']").attr("selected", "selected");
				zones_select.selectOptions("0", true);
			}
			
			if (typeof(return_zones) == "function") {
				return_zones();
			}
		});
	}
	else {
		if (typeof(return_no_zones) == "function") {
			return_no_zones();
		}
	}	
}

// ################################################################################

// Advanced location select #######################################################
// form_id, container, mode(selects/autocomplete), toggle_link, selected_country, selected_state, selected_city, selected_location
// label_country, label_state, label_city, label_location
function build_location_block(opt){
	
	// Get selection mode from cookie if toggle mode link is enabled
	if (($.cookie("location_mode") != null) && (opt.toggle_link > 0)) {
		opt.mode = $.cookie("location_mode");
	}
	
	// Extend default option
	var opt = $.extend({}, {
		mode              : "selects",
		err               : "",
		selected_location : "",
		country_key       : 0,
		country_name      : "fk_countries",
		country_id        : "fk_countries",
		state_name        : "fk_states",
		state_id          : "fk_states",
		city_name         : "fk_cities",
		city_id           : "fk_cities",
		city_callback     : function(){},
		location_name     : "fk_location",
		location_id       : "fk_location"
	}, opt);
	
	// Build required data hint
	var required;
	if (opt.required > 0) {
		required = " <span class=\"error_star\">*</span>";
	}
	else {
		required = "";
	}
	
	// Selection mode is advanced
	if (opt.mode == "selects") {
		if (opt.country_key > 0) {
			country_row = "";
		}
		else {
			country_row = "<li class=\"fr\"><label class=\"l\">" + opt.label_country + ":" + required + "</label><div class=\"r\"><select id=\"" + opt.country_id + "\" name=\"" + opt.country_name + "\"><option value=\"0\">" + txt_loading + "</option></select> " + opt.err + " <span id=\"change_link_container\"></span></div></li>";
		}
		
		// Empty the container and add 3 selects for country, state, city
		$("#" + opt.container).empty().append(country_row +
		"<li class=\"fr\"><label class=\"l\">" + opt.label_state + ":" + required + "</label><div class=\"r\"><select id=\"" + opt.state_id + "\" name=\"" + opt.state_name + "\"><option value=\"0\">" + txt_loading + "</option></select></div></li>" +
		"<li class=\"fr\"><label class=\"l\">" + opt.label_city + ":" + required + "</label><div class=\"r\"><select id=\"" + opt.city_id  + "\" name=\"" + opt.city_name + "\"><option value=\"0\">" + txt_loading + "</option></select></div></li>");
		
		if (opt.country_key > 0) {
			// Callback function on populate_countries change is populate_states
			populate_states({
				form_id             : opt.form_id,
				country_key         : opt.country_key,
				select_id_countries : opt.country_id,
				select_id_states    : opt.state_id,
				select_id_cities    : opt.city_id,
				selected_state      : opt.selected_state
			}, function(){
				// Callback function on populate_states change is populate_cities
				populate_cities({
					form_id          : opt.form_id,
					select_id_states : opt.state_id,
					select_id_cities : opt.city_id,
					selected_city    : opt.selected_city
				}, opt.city_callback);
			});
		}
		else {
			// Call populate_countries
			populate_countries({
				form_id             : opt.form_id,
				select_id_countries : opt.country_id,
				select_id_states    : opt.state_id,
				select_id_cities    : opt.city_id,
				selected_country    : opt.selected_country
			}, function(){
				// Callback function on populate_countries change is populate_states
				populate_states({
					form_id             : opt.form_id,
					select_id_countries : opt.country_id,
					select_id_states    : opt.state_id,
					select_id_cities    : opt.city_id,
					selected_state      : opt.selected_state
				}, function(){
					// Callback function on populate_states change is populate_cities
					populate_cities({
						form_id          : opt.form_id,
						select_id_states : opt.state_id,
						select_id_cities : opt.city_id,
						selected_city    : opt.selected_city
					}, opt.city_callback);
				});
			});
		}
	}
	// Selection mode is simple
	else if (opt.mode == "autocomplete") {
		// Empty the container and add a textbox and 3 hidden imputs
		$("#" + opt.container).empty().append("<li class=\"fr\"><input type=\"hidden\" id=\"" + opt.country_id + "\" name=\"" + opt.country_name + "\" value=\"" + opt.selected_country + "\">" +
		"<input type=\"hidden\" id=\"" + opt.state_id + "\" name=\"" + opt.state_name + "\" value=\"" + opt.selected_state + "\">" +
		"<input type=\"hidden\" id=\"" + opt.city_id + "\" name=\"" + opt.city_name + "\" value=\"" + opt.selected_city + "\">" +
		"<label for=\"" + opt.location_id + "\" class=\"l\">" + opt.label_location + ":" + required + "</label><div class=\"r\"><input type=\"text\" id=\"" + opt.location_id + "\" name=\"" + opt.location_name + "\" value=\"" + opt.selected_location + "\" class=\"txt\" style=\"width: 20em;\" maxlength=\"255\" size=\"40\" /> " + opt.err + " <span id=\"change_link_container\"></span><p class=\"hint\">" + opt.hint_location + "</p></div></li>");
		
		// Init autocompleter
		$("#" + opt.location_id).autocompleteShow({
			matchSubset        : false,
			minChars           : 2,
			request            : "autocomplete_city",
			remote_connector   : "site.remote",
			result_fields_id   : opt.city_id + "," + opt.state_id + "," + opt.country_id,
			result_fields_name : opt.city_name + "," + opt.state_name + "," + opt.country_name,
			form_id            : opt.form_id
		});
	}
	
	// Toggle selection mode link is enabled
	if (opt.toggle_link > 0) {
		var txt_toggle_link
		// Get text for toggle link
		if (opt.mode == "autocomplete") {
			txt_toggle_link = opt.txt_toggle_link_advanced;
		}
		else if (opt.mode == "selects") {
			txt_toggle_link = opt.txt_toggle_link_simple;
		}
		
		// Assign link action
		var link = $("<a href=\"#\" class=\"dark small\">" + txt_toggle_link + "</a>").click(function(e){
			// Change to advanced
			if (opt.mode == "autocomplete") {
				// Remove autocomplete
				$(".ac_results").remove();
				
				// Define new mode
				opt.mode = "selects";
				// Get values from hidden imputs
				opt.selected_country = $(":hidden#" + opt.country_id, "#" + opt.form_id).attr("value");
				opt.selected_state = $(":hidden#" + opt.state_id, "#" + opt.form_id).attr("value");
				opt.selected_city = $(":hidden#" + opt.city_id, "#" + opt.form_id).attr("value");
			}
			else {
				// Define new mode
				opt.mode = "autocomplete";
				// Get values from hidden imputs
				opt.selected_country = $("#" + opt.country_id, "#" + opt.form_id).getOption();
				opt.selected_state = $("#" + opt.state_id, "#" + opt.form_id).getOption();
				opt.selected_city = $("#" + opt.city_id, "#" + opt.form_id).getOption();
				
				// Full location is selected
				if ($("#fk_cities", "#" + opt.form_id).val() > 0) {
					// Append location data
					opt.selected_location = $("#" + opt.city_id + " :selected", "#" + opt.form_id).text() + ", " + $("#" + opt.state_id + " :selected", "#" + opt.form_id).text() + ", " + $("#" + opt.country_id + " :selected", "#" + opt.form_id).text();
				}
				else {
					opt.selected_location = "";
				}
			}
			
			// Set new selection mode in cookie
			$.cookie("location_mode", opt.mode, {path: "/"})
			// Rebuild location block with new options
			build_location_block(opt);
			
			return false;
		});
		// Add toggle mode link
		$("#change_link_container", "#" + opt.container).append(link);
	}
}

// ################################################################################
;;(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($){ 
	
	$.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);  
;;(function($){var helper={},current,title,tID,IE=$.browser.msie&&/MSIE\s(5\.5|6\.)/.test(navigator.userAgent),track=false;$.tooltip={blocked:false,defaults:{delay:200,fade:false,showURL:true,extraClass:"",top:15,left:15,id:"tooltip"},block:function(){$.tooltip.blocked=!$.tooltip.blocked;}};$.fn.extend({tooltip:function(settings){settings=$.extend({},$.tooltip.defaults,settings);createHelper(settings);return this.each(function(){$.data(this,"tooltip",settings);this.tOpacity=helper.parent.css("opacity");this.tooltipText=this.title;$(this).removeAttr("title");this.alt="";}).mouseover(save).mouseout(hide).click(hide);},fixPNG:IE?function(){return this.each(function(){var image=$(this).css('backgroundImage');if(image.match(/^url\(["']?(.*\.png)["']?\)$/i)){image=RegExp.$1;$(this).css({'backgroundImage':'none','filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='"+image+"')"}).each(function(){var position=$(this).css('position');if(position!='absolute'&&position!='relative')$(this).css('position','relative');});}});}:function(){return this;},unfixPNG:IE?function(){return this.each(function(){$(this).css({'filter':'',backgroundImage:''});});}:function(){return this;},hideWhenEmpty:function(){return this.each(function(){$(this)[$(this).html()?"show":"hide"]();});},url:function(){return this.attr('href')||this.attr('src');}});function createHelper(settings){if(helper.parent)return;helper.parent=$('<div id="'+settings.id+'"><h3></h3><div class="body"></div><div class="url"></div></div>').appendTo(document.body).hide();if($.fn.bgiframe)helper.parent.bgiframe();helper.title=$('h3',helper.parent);helper.body=$('div.body',helper.parent);helper.url=$('div.url',helper.parent);}function settings(element){return $.data(element,"tooltip");}function handle(event){if(settings(this).delay)tID=setTimeout(show,settings(this).delay);else
show();track=!!settings(this).track;$(document.body).bind('mousemove',update);update(event);}function save(){if($.tooltip.blocked||this==current||(!this.tooltipText&&!settings(this).bodyHandler))return;current=this;title=this.tooltipText;if(settings(this).bodyHandler){helper.title.hide();var bodyContent=settings(this).bodyHandler.call(this);if(bodyContent.nodeType||bodyContent.jquery){helper.body.empty().append(bodyContent)}else{helper.body.html(bodyContent);}helper.body.show();}else if(settings(this).showBody){var parts=title.split(settings(this).showBody);helper.title.html(parts.shift()).show();helper.body.empty();for(var i=0,part;(part=parts[i]);i++){if(i>0)helper.body.append("<br/>");helper.body.append(part);}helper.body.hideWhenEmpty();}else{helper.title.html(title).show();helper.body.hide();}if(settings(this).showURL&&$(this).url())helper.url.html($(this).url().replace('http://','')).show();else
helper.url.hide();helper.parent.addClass(settings(this).extraClass);if(settings(this).fixPNG)helper.parent.fixPNG();handle.apply(this,arguments);}function show(){tID=null;if((!IE||!$.fn.bgiframe)&&settings(current).fade){if(helper.parent.is(":animated"))helper.parent.stop().show().fadeTo(settings(current).fade,current.tOpacity);else
helper.parent.is(':visible')?helper.parent.fadeTo(settings(current).fade,current.tOpacity):helper.parent.fadeIn(settings(current).fade);}else{helper.parent.show();}update();}function update(event){if($.tooltip.blocked)return;if(event&&event.target.tagName=="OPTION"){return;}if(!track&&helper.parent.is(":visible")){$(document.body).unbind('mousemove',update)}if(current==null){$(document.body).unbind('mousemove',update);return;}helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");var left=helper.parent[0].offsetLeft;var top=helper.parent[0].offsetTop;if(event){left=event.pageX+settings(current).left;top=event.pageY+settings(current).top;var right='auto';if(settings(current).positionLeft){right=$(window).width()-left;left='auto';}helper.parent.css({left:left,right:right,top:top});}var v=viewport(),h=helper.parent[0];if(v.x+v.cx<h.offsetLeft+h.offsetWidth){left-=h.offsetWidth+20+settings(current).left;helper.parent.css({left:left+'px'}).addClass("viewport-right");}if(v.y+v.cy<h.offsetTop+h.offsetHeight){top-=h.offsetHeight+20+settings(current).top;helper.parent.css({top:top+'px'}).addClass("viewport-bottom");}}function viewport(){return{x:$(window).scrollLeft(),y:$(window).scrollTop(),cx:$(window).width(),cy:$(window).height()};}function hide(event){if($.tooltip.blocked)return;if(tID)clearTimeout(tID);current=null;var tsettings=settings(this);function complete(){helper.parent.removeClass(tsettings.extraClass).hide().css("opacity","");}if((!IE||!$.fn.bgiframe)&&tsettings.fade){if(helper.parent.is(':animated'))helper.parent.stop().fadeTo(tsettings.fade,0,complete);else
helper.parent.stop().fadeOut(tsettings.fade,complete);}else
complete();if(settings(this).fixPNG)helper.parent.unfixPNG();}})(jQuery); 
;(function(c){function r(b,d){d=d==="x"?m.width():m.height();return typeof b==="string"?Math.round(b.match(/%/)?d/100*parseInt(b,10):parseInt(b,10)):b}function M(b){b=c.isFunction(b)?b.call(i):b;return a.photo||b.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i)}function Y(){for(var b in a)if(c.isFunction(a[b])&&b.substring(0,2)!=="on")a[b]=a[b].call(i);a.rel=a.rel||i.rel;a.href=a.href||i.href;a.title=a.title||i.title}function Z(b){i=b;a=c(i).data(q);Y();if(a.rel&&a.rel!=="nofollow"){g= c(".cboxElement").filter(function(){return(c(this).data(q).rel||this.rel)===a.rel});j=g.index(i);if(j<0){g=g.add(i);j=g.length-1}}else{g=c(i);j=0}if(!B){C=B=n;N=i;N.blur();c(document).bind("keydown.cbox_close",function(d){if(d.keyCode===27){d.preventDefault();e.close()}}).bind("keydown.cbox_arrows",function(d){if(g.length>1)if(d.keyCode===37){d.preventDefault();D.click()}else if(d.keyCode===39){d.preventDefault();E.click()}});a.overlayClose&&s.css({cursor:"pointer"}).one("click",e.close);c.event.trigger(aa); a.onOpen&&a.onOpen.call(i);s.css({opacity:a.opacity}).show();a.w=r(a.initialWidth,"x");a.h=r(a.initialHeight,"y");e.position(0);O&&m.bind("resize.cboxie6 scroll.cboxie6",function(){s.css({width:m.width(),height:m.height(),top:m.scrollTop(),left:m.scrollLeft()})}).trigger("scroll.cboxie6")}P.add(D).add(E).add(t).add(Q).hide();R.html(a.close).show();e.slideshow();e.load()}var q="colorbox",F="hover",n=true,e,x=c.browser.msie&&!c.support.opacity,O=x&&c.browser.version<7,aa="cbox_open",H="cbox_load",S= "cbox_complete",T="resize.cbox_resize",s,k,u,p,U,V,W,X,g,m,l,I,J,K,Q,P,t,E,D,R,y,z,v,w,i,N,j,a,B,C,$={transition:"elastic",speed:350,width:false,height:false,innerWidth:false,innerHeight:false,initialWidth:"400",initialHeight:"400",maxWidth:false,maxHeight:false,scalePhotos:n,scrolling:n,inline:false,html:false,iframe:false,photo:false,href:false,title:false,rel:false,opacity:0.9,preloading:n,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:false,overlayClose:n, slideshow:false,slideshowAuto:n,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:false,onLoad:false,onComplete:false,onCleanup:false,onClosed:false};e=c.fn.colorbox=function(b,d){var h=this;if(!h.length)if(h.selector===""){h=c("<a/>");b.open=n}else return this;h.each(function(){var f=c.extend({},c(this).data(q)?c(this).data(q):$,b);c(this).data(q,f).addClass("cboxElement");if(d)c(this).data(q).onComplete=d});b&&b.open&&Z(h);return this};e.init=function(){function b(d){return c('<div id="cbox'+ d+'"/>')}m=c(window);k=c('<div id="colorbox"/>');s=b("Overlay").hide();u=b("Wrapper");p=b("Content").append(l=b("LoadedContent").css({width:0,height:0}),J=b("LoadingOverlay"),K=b("LoadingGraphic"),Q=b("Title"),P=b("Current"),t=b("Slideshow"),E=b("Next"),D=b("Previous"),R=b("Close"));u.append(c("<div/>").append(b("TopLeft"),U=b("TopCenter"),b("TopRight")),c("<div/>").append(V=b("MiddleLeft"),p,W=b("MiddleRight")),c("<div/>").append(b("BottomLeft"),X=b("BottomCenter"),b("BottomRight"))).children().children().css({"float":"left"}); I=c("<div style='position:absolute; top:0; left:0; width:9999px; height:0;'/>");c("body").prepend(s,k.append(u,I));if(x){k.addClass("cboxIE");O&&s.css("position","absolute")}p.children().bind("mouseover mouseout",function(){c(this).toggleClass(F)}).addClass(F);y=U.height()+X.height()+p.outerHeight(n)-p.height();z=V.width()+W.width()+p.outerWidth(n)-p.width();v=l.outerHeight(n);w=l.outerWidth(n);k.css({"padding-bottom":y,"padding-right":z}).hide();E.click(e.next);D.click(e.prev);R.click(e.close);p.children().removeClass(F); c(".cboxElement").live("click",function(d){if(d.button!==0&&typeof d.button!=="undefined")return n;else{Z(this);return false}})};e.position=function(b,d){function h(A){U[0].style.width=X[0].style.width=p[0].style.width=A.style.width;K[0].style.height=J[0].style.height=p[0].style.height=V[0].style.height=W[0].style.height=A.style.height}var f=m.height();f=Math.max(f-a.h-v-y,0)/2+m.scrollTop();var o=Math.max(document.documentElement.clientWidth-a.w-w-z,0)/2+m.scrollLeft();b=k.width()===a.w+w&&k.height()=== a.h+v?0:b;u[0].style.width=u[0].style.height="9999px";k.dequeue().animate({width:a.w+w,height:a.h+v,top:f,left:o},{duration:b,complete:function(){h(this);C=false;u[0].style.width=a.w+w+z+"px";u[0].style.height=a.h+v+y+"px";d&&d()},step:function(){h(this)}})};e.resize=function(b){function d(){a.w=a.w||l.width();a.w=a.mw&&a.mw<a.w?a.mw:a.w;return a.w}function h(){a.h=a.h||l.height();a.h=a.mh&&a.mh<a.h?a.mh:a.h;return a.h}function f(G){e.position(G,function(){if(B){if(x){A&&l.fadeIn(100);k[0].style.removeAttribute("filter")}if(a.iframe)l.append("<iframe id='cboxIframe'"+ (a.scrolling?" ":"scrolling='no'")+" name='iframe_"+(new Date).getTime()+"' frameborder=0 src='"+a.href+"' "+(x?"allowtransparency='true'":"")+" />");l.show();Q.show().html(a.title);if(g.length>1){P.html(a.current.replace(/\{current\}/,j+1).replace(/\{total\}/,g.length)).show();E.html(a.next).show();D.html(a.previous).show();a.slideshow&&t.show()}J.hide();K.hide();c.event.trigger(S);a.onComplete&&a.onComplete.call(i);a.transition==="fade"&&k.fadeTo(L,1,function(){x&&k[0].style.removeAttribute("filter")}); m.bind(T,function(){e.position(0)})}})}if(B){var o,A,L=a.transition==="none"?0:a.speed;m.unbind(T);if(b){l.remove();l=c('<div id="cboxLoadedContent"/>').html(b);l.hide().appendTo(I).css({width:d(),overflow:a.scrolling?"auto":"hidden"}).css({height:h()}).prependTo(p);c("#cboxPhoto").css({cssFloat:"none"});O&&c("select:not(#colorbox select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("cbox_cleanup",function(){this.style.visibility="inherit"});a.transition=== "fade"&&k.fadeTo(L,0,function(){f(0)})||f(L);if(a.preloading&&g.length>1){b=j>0?g[j-1]:g[g.length-1];o=j<g.length-1?g[j+1]:g[0];o=c(o).data(q).href||o.href;b=c(b).data(q).href||b.href;M(o)&&c("<img />").attr("src",o);M(b)&&c("<img />").attr("src",b)}}else setTimeout(function(){var G=l.wrapInner("<div style='overflow:auto'></div>").children();a.h=G.height();l.css({height:a.h});G.replaceWith(G.children());e.position(L)},1)}};e.load=function(){var b,d,h,f=e.resize;C=n;i=g[j];a=c(i).data(q);Y();c.event.trigger(H); a.onLoad&&a.onLoad.call(i);a.h=a.height?r(a.height,"y")-v-y:a.innerHeight?r(a.innerHeight,"y"):false;a.w=a.width?r(a.width,"x")-w-z:a.innerWidth?r(a.innerWidth,"x"):false;a.mw=a.w;a.mh=a.h;if(a.maxWidth){a.mw=r(a.maxWidth,"x")-w-z;a.mw=a.w&&a.w<a.mw?a.w:a.mw}if(a.maxHeight){a.mh=r(a.maxHeight,"y")-v-y;a.mh=a.h&&a.h<a.mh?a.h:a.mh}b=a.href;J.show();K.show();if(a.inline){c('<div id="cboxInlineTemp" />').hide().insertBefore(c(b)[0]).bind(H+" cbox_cleanup",function(){c(this).replaceWith(l.children())}); f(c(b))}else if(a.iframe)f(" ");else if(a.html)f(a.html);else if(M(b)){d=new Image;d.onload=function(){var o;d.onload=null;d.id="cboxPhoto";c(d).css({margin:"auto",border:"none",display:"block",cssFloat:"left"});if(a.scalePhotos){h=function(){d.height-=d.height*o;d.width-=d.width*o};if(a.mw&&d.width>a.mw){o=(d.width-a.mw)/d.width;h()}if(a.mh&&d.height>a.mh){o=(d.height-a.mh)/d.height;h()}}if(a.h)d.style.marginTop=Math.max(a.h-d.height,0)/2+"px";f(d);g.length>1&&c(d).css({cursor:"pointer"}).click(e.next); if(x)d.style.msInterpolationMode="bicubic"};d.src=b}else c("<div />").appendTo(I).load(b,function(o,A){A==="success"?f(this):f(c("<p>Request unsuccessful.</p>"))})};e.next=function(){if(!C){j=j<g.length-1?j+1:0;e.load()}};e.prev=function(){if(!C){j=j>0?j-1:g.length-1;e.load()}};e.slideshow=function(){function b(){t.text(a.slideshowStop).bind(S,function(){h=setTimeout(e.next,a.slideshowSpeed)}).bind(H,function(){clearTimeout(h)}).one("click",function(){d();c(this).removeClass(F)});k.removeClass(f+ "off").addClass(f+"on")}var d,h,f="cboxSlideshow_";t.bind("cbox_closed",function(){t.unbind();clearTimeout(h);k.removeClass(f+"off "+f+"on")});d=function(){clearTimeout(h);t.text(a.slideshowStart).unbind(S+" "+H).one("click",function(){b();h=setTimeout(e.next,a.slideshowSpeed);c(this).removeClass(F)});k.removeClass(f+"on").addClass(f+"off")};if(a.slideshow&&g.length>1)a.slideshowAuto?b():d()};e.close=function(){c.event.trigger("cbox_cleanup");a.onCleanup&&a.onCleanup.call(i);B=false;c(document).unbind("keydown.cbox_close keydown.cbox_arrows"); m.unbind(T+" resize.cboxie6 scroll.cboxie6");s.css({cursor:"auto"}).fadeOut("fast");k.stop(n,false).fadeOut("fast",function(){c("#colorbox iframe").attr("src","about:blank");l.remove();k.css({opacity:1});try{N.focus()}catch(b){}c.event.trigger("cbox_closed");a.onClosed&&a.onClosed.call(i)})};e.element=function(){return c(i)};e.settings=$;c(e.init)})(jQuery);