/*
$(function() {
    $("select")
        .mouseover(function(){
            $(this)
                .data("origWidth", $(this).css("width"))
                .css("width", "auto");
        })
        .mouseout(function(){
            $(this).css("width", $(this).data("origWidth"));
        });

});
*/

$(function() {
	$("option").mouseover(function(){
		$(this).attr('title',$(this).val());
	});
});

/*
	Objekt filter() v sobe drzi informace o vsech filtrech a o aktivnim 
*/
function filter() {
	this.pocetFilteru = 8;
	this.name = "";
	this.sirka = "";
	this.filter = Array(); // pole filtrů
	
	this.delky = Array("4,2","6,3","8,4","10,5","12,6","14,7","16,8");
	this.kolejiste = Array("jednostrané STANDART", "jednostrané nízke", "oboustrané STANDART", "oboustrané nízké");
	this.vypln = Array("polykarbonát 10 mm čirý", "polykarbonát 10 mm barevný", "polykarbonát 10 mm No Drop", "AC 4 mm");
	this.bool = Array("ano", "ne");
	
/* --- MARS --- */
	this.filter["mars"] = {
		typ: "mars",
		sirka: Array("3,0","3,5","4,0","4,5","5,0","5,5","6,0"),
		delka: Array(Array()),
		kolejiste: this.kolejiste,
		vypln: this.vypln,
		vystuzeni: this.bool,
		montaz: this.bool
	}
	this.filter["mars"].delka["3,0"] = this.delky;
	this.filter["mars"].delka["3,5"] = this.delky;
	this.filter["mars"].delka["4,0"] = this.delky;
	this.filter["mars"].delka["4,5"] = this.delky;
	this.filter["mars"].delka["5,0"] = this.delky;
	this.filter["mars"].delka["5,5"] = this.delky;
	this.filter["mars"].delka["6,0"] = this.delky;
	
/* --- JUPITER --- */
	this.filter["jupiter"] = {
		typ: "jupiter",
		sirka: Array("4,0","4,5","5,0","6,0"),
		delka: Array(Array()),
		kolejiste: this.kolejiste,
		vypln: this.vypln,
		vystuzeni: this.bool,
		montaz: this.bool
	}
	this.filter["jupiter"].delka["4,0"] = this.delky;
	this.filter["jupiter"].delka["4,5"] = this.delky;
	this.filter["jupiter"].delka["5,0"] = this.delky;
	this.filter["jupiter"].delka["6,0"] = this.delky;
	
/* --- SATURN --- */
	this.filter["saturn"] = {
		typ: "saturn",
		sirka: Array("4,0","4,5","5,0","6,0"),
		delka: Array(Array()),
		kolejiste: this.kolejiste,
		vypln: this.vypln,
		vystuzeni: this.bool,
		montaz: this.bool
	}
	this.filter["saturn"].delka["4,0"] = this.delky;
	this.filter["saturn"].delka["4,5"] = this.delky;
	this.filter["saturn"].delka["5,0"] = this.delky;
	this.filter["saturn"].delka["6,0"] = Array("4,2","6,3","8,4","10,5","12,6");
	
/* --- URAN --- */
	this.filter["uran"] = {
		typ: "uran",
		sirka: Array("3,0","4,0","4,5","5,0","6,0"),
		delka: Array(Array()),
		kolejiste: this.kolejiste,
		vypln: this.vypln,
		vystuzeni: this.bool,
		montaz: this.bool
	}
	this.filter["uran"].delka["3,0"] = this.delky;
	this.filter["uran"].delka["4,0"] = this.delky;
	this.filter["uran"].delka["4,5"] = this.delky;
	this.filter["uran"].delka["5,0"] = Array("4,2","6,3","8,4","10,5","12,6","14,7");
	this.filter["uran"].delka["6,0"] = Array("4,2","6,3","8,4","10,5","12,6");
	
/* --- NEPTUN --- */
	this.filter["neptun"] = {
		typ: "neptun",
		sirka: Array("4,0","4,5","5,0","6,0"),
		delka: Array(Array()),
		kolejiste: this.kolejiste,
		vypln: this.vypln,
		vystuzeni: this.bool,
		montaz: this.bool
	}
	this.filter["neptun"].delka["4,0"] = this.delky;
	this.filter["neptun"].delka["4,5"] = this.delky;
	this.filter["neptun"].delka["5,0"] = Array("4,2","6,3","8,4","10,5","12,6","14,7");
	this.filter["neptun"].delka["6,0"] = Array("4,2","6,3","8,4","10,5","12,6");
	
/* --- PLUTO --- */
	this.filter["pluto"] = {
		typ: "pluto",
		sirka: Array("3,5","4,0","4,5","5,0"),
		delka: Array(Array()),
		kolejiste: this.kolejiste,
		vypln: this.vypln,
		vystuzeni: this.bool,
		montaz: this.bool
	}
	this.filter["pluto"].delka["3,5"] = this.delky;
	this.filter["pluto"].delka["4,0"] = this.delky;
	this.filter["pluto"].delka["4,5"] = this.delky;
	this.filter["pluto"].delka["5,0"] = this.delky;
	
/* --- royal --- */
	this.filter["royal"] = {
		typ: "royal",
		sirka: Array("4,0","5,0","6,0"),
		delka: Array(Array()),
		kolejiste: this.kolejiste,
		vypln: this.vypln,
		vystuzeni: this.bool,
		montaz: this.bool
	}
	this.filter["royal"].delka["4,0"] = this.delky;
	this.filter["royal"].delka["5,0"] = Array("4,2","6,3","8,4","10,5","12,6","14,7");
	this.filter["royal"].delka["6,0"] = Array("4,2","6,3","8,4","10,5","12,6");

/* ------ */

	this.setName = function(name) { this.name = name; }
	this.getName = function() { return this.name; }

	this.getProperty = function(property) { 
		if (typeof(this.filter[this.name]) == "undefined") return 0;
		else return this.filter[this.name][property];
	}
	
	this.getDelka = function(sirka) { 
		if (typeof(this.filter[this.name]) == "undefined") return 0;
		else return this.filter[this.name]["delka"][sirka];
	}
}
/* Generovani inputu */
function createRadio(name,value,fce) {
	return "<input onclick='" + fce + "' type='radio' class='radio' name='" + name + "' id='x" + value + "' value='" + value + "'>" +
				 "<label for='x" + value + "'>" + value + "</label>";
}
/* common function for filter */
function filterCommon(properity,heading,required,nextFilterNumber) {
	//chybi test vyplnenosti promennych
	var item = SF.getProperty(properity);
	var items = "<h2>" + heading + ": ";
	if (required) items += "<span class='required'>*</span>";
	items += "</h2>";
	if (!item) items += "ERROR: Filtr '" + SF.getName() + "' nebo jeho vlastnost '" + properity + "' nejsou nadefinovany!";
	else	for (i in item) items += createRadio(properity,item[i],'f' + nextFilterNumber + '()');
	items += "<div class='cleaner'></div>";
	for (i=nextFilterNumber; i<=SF.pocetFilteru; i++) {
		$(".swedFilter"+i).hide();
	}
	$(".swedFilter"+nextFilterNumber).hide().html(items).animate({height: 'toggle'}, 2000, function() {});
}


/* filtrovaci funce pro inputy (on click) */
function f1(i_name) {
	SF.setName($(".swedFilter1 input").attr('value'));
	var item = SF.getProperty("sirka");
	var items = "<h2>"+i_name+": <span class='required'>*</span></h2>";
	var poc = 1;
	if (!item) items += "ERROR: Filtr '" + SF.getName() + "' nebo jeho vlastnosti nejsou nadefinovany!";
	else
		for (i in item) {
			items += createRadio("sirka",item[i],'f2()');
			if (poc%4 == 0) items += "<div class='cleaner'></div>";
			poc = poc+1;
		}
	items += "<div class='cleaner'></div>";
	for (i=2; i<=SF.pocetFilteru; i++) {
		$(".swedFilter"+i).hide("slow");
	}
	$(".swedFilter2").hide("slow").html(items).show("slow");
};

function f2(i_name) {
	var sirka = $("form .swedFilter2 input:radio:checked").val();//$(this).attr('value');
	var item = SF.getDelka(sirka);
	var items = "<h2>"+i_name+": <span class='required'>*</span></h2>";
	if (!item) items += "ERROR: Filtr '" + SF.getName() + "' nebo jeho vlastnosti nejsou nadefinovany!";
	else for (i in item) items += createRadio("delka",item[i],'f3()');
	items += "<div class='cleaner'></div>";
	for (i=3; i<=SF.pocetFilteru; i++) {
		$(".swedFilter"+i).hide();
	}
	$(".swedFilter3").hide().html(items).show("slow");
}

/* Start */
if (typeof(SF) == "undefined") SF = new filter();

/*---------------------------------------------------------------------------*/
/*
$(document).ready(function(){
	$(".dodani").change(function(){
		$(".rozmery").hide("slow");
		sId = $(this).attr("id");
		$("."+sId).show("slow");
	});

	$(".jiny_tvar").change(function(){
		$(".descript").toggle("slow");
	});
});
*/
