$(document).ready(function() {
	// accordion for index #column1
	if($("#column1 .accordion").length > 0) {
		var table = $("#column1 .accordion table");
		table.next("p").remove();
		 
		var titles = new Array();
		table.find("h3").each(function() {
			titles.push($.trim($(this).html()));
			$(this).parents("tr").remove();
		});
		
		var texts = new Array();
		table.find("td").each(function(){
			texts.push($.trim($(this).html()));
		});
		
		table.before("<div id='gredi-accordion' style='display: none;' />");
		var a = table.siblings("#gredi-accordion");
		table.remove();
		
		for(var i = 0; i < titles.length; i++) {
			a.append("<h3>"+titles[i]+"</h3>");
			a.append("<p>"+texts[i]+"</p>");
		}
		
		//a.children("h3:first").addClass("open");
		//a.children("p:first").addClass("open");
		a.children("p:not(.open)").hide();
		
		
		a.find("h3").bind("click", function(e) {
			e.preventDefault();
			
			if(!$(this).hasClass("open")) {
				a.children("p.open").addClass("closing");
				a.children().removeClass("open");
				
				
				$(this).addClass("open");
				$(this).next("p").addClass("open");
				
				a.find("p.closing").slideUp(400).removeClass("closing");
				$(this).next("p.open").slideDown(400);
			}
		});
		a.show();
	}
	
	var badIE = false;
	if($.browser.msie && ($.browser.version == "7.0" || $.browser.version == "6.0")) {
		badIE = true;
	}
	
	// Navigations
	if(!badIE) {
		var nav = $("#nav");
		var navTuotteet = nav.children("ul").children("li:nth-child(2)").addClass("dropdown");
		var navPalvelut = nav.children("ul").children("li:nth-child(3)").addClass("dropdown");
		var contentTuotteet = $(".navTuotteet");
		var contentPalvelut = $(".navPalvelut");
		
		contentTuotteet.find("table").next("p").remove();
		contentPalvelut.find("table").next("p").remove();
		
		contentTuotteet.find("td").each(function() {
			$(this).find("a").text("");
			var aTmp = $(this).find("a").parent("p").html();
			$(this).find("a").parent("p").remove();
			$(this).append(aTmp);
			
			var tdContent = $(this).html();
			$(this).html("<div class='td'>"+tdContent+"</td>");
		});
		contentTuotteet.find("tr").children("td:not(:last)").css("border-right", "1px solid #e8e8e8");
		navTuotteet.append(contentTuotteet);
		navTuotteet.bind("mouseover", function(e) {
			var h = contentTuotteet.children().height();
			contentTuotteet.css("z-index", "9999");
			contentTuotteet.stop().animate({
				height: h
			}, 500);
		});
		navTuotteet.bind("mouseout", function(e) {
			contentTuotteet.css("z-index", "9998");
			contentTuotteet.stop().animate({
				height: 0
			}, 300);
		});
		
		contentPalvelut.find("td").each(function() {
			$(this).find("a").text("");
			var aTmp = $(this).find("a").parent("p").html();
			$(this).find("a").parent("p").remove();
			$(this).append(aTmp);
			
			var tdContent = $(this).html();
			$(this).html("<div class='td'>"+tdContent+"</td>");
		});
		contentPalvelut.find("tr").children("td:not(:last)").css("border-right", "1px solid #e8e8e8");
		navPalvelut.append(contentPalvelut);
		navPalvelut.bind("mouseover", function(e) {
			var h = contentPalvelut.children().height();
			contentPalvelut.css("z-index", "9999");
			contentPalvelut.stop().animate({
				height: h
			}, 500);
		});
		navPalvelut.bind("mouseout", function(e) {
			contentPalvelut.css("z-index", "9998");
			contentPalvelut.stop().animate({
				height: 0
			}, 300);
		});
	}

	$(".reallytab table").each(function() {
		$(this).find("tr:even").css("background", "#f7f7f7");
	})
});
