var meistrimees = {
	str: {
		search: "Otsi...",
		newsletter: "Sisestage email...",
		no_sub: "Palun valige vasakult menüüst alamkataloog."
	},
	startMenu: function(){
		jQuery(".pood_kataloog_treeview").addClass("treeview-gray").treeview({
			collapsed: true,
			unique: true,
			persist: "location",
			animated: "fast"
		});
	},
	eemaldaKataloog: function(){
		jQuery("table.tootekataloog_piltidega").remove();
	},
	kataloogiHoidja: function(state){
		switch(state){
			default:
				jQuery("#kataloogi_hoidja").remove();
			break;
			case true:
				jQuery("#kataloogi_hoidja").show();
			break;
		}
	}
}
jQuery(document).ready(function(){
	jQuery('.news-ticker-list').innerfade({
				speed: 'slow',
				timeout: 6000,
				type: "random",
				containerheight: '30px'
			});
/*
	if(jQuery(".cr_sisukord").html()){
		jQuery(".cr_sisukord a").addClass("sub");
		var buffer = jQuery(".cr_sisukord").html();
		jQuery(".cr_sisukord").remove();
		jQuery("#submenu_sisu").html('<ul id="submenu_ul">' + buffer + "</ul>");
	}
*/
	
	jQuery("input#uudislist_nupp").remove();
	jQuery("input#uudislist_input").val(meistrimees.str.newsletter);
	jQuery("input#uudislist_input").focus(function(){
		if(jQuery(this).val() == meistrimees.str.newsletter) { jQuery(this).val("") }
	})
	jQuery("input#uudislist_input").blur(function(){
		if(jQuery(this).val() == "") { jQuery(this).val(meistrimees.str.newsletter) }
	})
	

	jQuery("select.toote_valikud").change(function(){
		jQuery("td.toote_hind").html(jQuery("select.toote_valikud option:selected").attr("rel"))

	})


/* 	Seadistame otsingu */
	if(jQuery("#pood_edukas_tellimus").html()){
		jQuery("#poe_otsing").remove();
	}
	jQuery("input#otsing").val(meistrimees.str.search);
	jQuery("input#otsing").focus(function(){
		if(jQuery(this).val() == meistrimees.str.search) { jQuery(this).val("") }
	})
	jQuery("input#otsing").blur(function(){
		if(jQuery(this).val() == "") { jQuery(this).val(meistrimees.str.search) }
	})
	
	
	if(jQuery("#pood_otsing_tulemus").html()){
		meistrimees.eemaldaKataloog();
		jQuery("div#content").html(jQuery("#pood_otsing_tulemus").html());
		jQuery("#pood_otsing_tulemus").remove();
	}
	
	
	var aadress = window.location.href;
	
/*
	if(jQuery("form[name='toote_tellimine']").html()){
		document.title = jQuery(".toote_nimi").text() + " | " + "Meistrimees";
		jQuery("div#sisu h1").text(jQuery(".toote_nimi").text());
	}
*/
	if(jQuery("#kat_holder").html()){
/*
		if(jQuery("#kat_title").html()){
			document.title = jQuery("#kat_title").text() + " | " + "Meistrimees";
			jQuery("div#sisu h1").text(jQuery("#kat_title").text());
			
		}
*/
		jQuery("#kat_holder").remove();
		meistrimees.kataloogiHoidja(true);
		meistrimees.startMenu();
	
	} else {		
		if(jQuery("table.toote_tabel").html()){
			meistrimees.kataloogiHoidja(true);
			meistrimees.startMenu();
		} else {
			meistrimees.kataloogiHoidja(false);
		}
	}
	jQuery("a.go_to_top").click(function(){
		window.location.href = window.location.href + "#top";
	})
	if((aadress.search(/katid/) > 0) || (aadress.search(/toode/) > 0) || (aadress.search(/add_ok_tooted/) > 0)){
		meistrimees.eemaldaKataloog();
		if(jQuery("#content").text() == "\n"){
			jQuery("#content").text(meistrimees.str.no_sub);
		}
	}
	jQuery("#loader").remove();
	jQuery("div#body").show();
})