$(document).ready(function(){
    
	/* Prevent duplicate news item headings */
	if ($("#newsTop a").html() == $("#NewsTitle").html()) {
		$("#newsTop").css("display","none");
	}
	
	// paapalstan kuvilta pois float jos kuvan leveys yli 480 px
    $("#mainCol p img").each(function() {
        var leveys = $(this).attr("width");
        if (leveys > 480) {
          $(this).css({float: "none", marginLeft: "0"});
        }
    });

    // safari peiskaa
    var isSafari = false;
    if(window.devicePixelRatio) isSafari = true;

    if(isSafari == true) {
       $("td.mapArea").css({height: "305px"});
       $("table.parkMap").css({width: "528px"});
       $("td.tab a").css({marginLeft: "-1px"});
       $("body.f img#bt, body.en img#bt").css({marginTop: "-3px"});
    }

    // sahkoposteille defuskaatio
    $("#copyright a").defuscate();

    // Sivuston varjot
    var pc = $("body").attr("class");
    var sh = $("#contentArea").height();
        // etusivulta vahan pois.
        if(pc == 'f') { sh -= 18; }
    // ie6:lta pois kanssa
    var browser = $.browser.name;
    var browserv = $.browser.versionNumber;
    // alert(browser + " " + browserv);
    if (browser == "msie" && browserv == 6) {
           sh -= 17;
    }
    $("#shadowleft, #shadowright").css({height: sh + "px"});
    // Etusivulta etusivulinkki pois
    $(".menuF li:first").remove();


    // Valikon nurkat

    $("#menuContainer > ul > li:first").addClass("first");
    $("#menuContainer > ul > li:last").addClass("last");
    $("body.en #menuContainer > ul > ul > li:first").addClass("first");
    $("body.en #menuContainer > ul > ul > li:last").addClass("last");
    $("body.en div.allNewsLink a").html("All news").attr("href","/news");
	$("body.ru #menuContainer > ul > ul > li:first").addClass("first");
    $("body.ru #menuContainer > ul > ul > li:last").addClass("last");


    // Nosteen hoveri koko alueelta

    $(".noste").hover(

        function() {

            $(this).css({background: "url('img/bullet-noste-s.gif') no-repeat 0 3px"});
            $(this).find("p").css({color: "#000000"});
            $(this).css({cursor: "pointer"});

        },

        function() {

            $(this).css({background: "url('img/bullet-noste.gif') no-repeat 0 3px"});
            $(this).find("p").css({color: "#4c4c4c"});
            $(this).css({cursor: "default"});

        }

    );

    // Noste kokonaan linkiksi

    $(".noste").click(function() {

        var link = $(this).find("a").attr("href");

        window.location = link;

    });

    // Noste2 alareunan luonti + marginaalidivi jolla korkeusongelma korjaantuu
    $(".noste2").append("<div class='noste2b'></div>");
    $(".noste2").after("<div class='noste2m'></div>");

    // Pysakointilaitokset
        // Kartat
        if (GBrowserIsCompatible()) {
            var map1f = new GMap2(document.getElementById("map1f"));
		    map1f.disableDragging();
            // hki
            map1f.setCenter(new GLatLng( 60.166024,24.934158), 13);

            var map2f = new GMap2(document.getElementById("map2f"));
			map2f.disableDragging();
            // tku
            map2f.setCenter(new GLatLng(60.449731,22.26285), 15);
        }

    // Kaupungin valintatabit
    $(".tab a").click(function() {

        // Merkitse valituksi
        $(".tab a").removeClass("s");
        $(this).addClass("s");

        // Aseta kaupunki
        var city = $(this).attr('id');

        // Piilota linkit
        $(".mapLinks div").hide();

        // Nayta valitun kaupungin linkit
        // (vaihdetaan tassa myös kartta?)

        $(".mapLinks ." + city).show();

        if (city == "hki") {
            $("#map2f, #map2fCover").css({display: "none"});
            $("#map1f, #map1fCover").css({display: "block"});
        } else {
            $("#map1f, #map1fCover").css({display: "none"});
            $("#map2f, #map2fCover").css({display: "block", visibility: "visible"});
        }

        return false;

    });

    // Kartan hoverit
    $("#map1fCover a, #map2fCover a").hover(function() {
        $(this).addClass("hov");
        var hoverid = $(this).attr("id");
        $(".mapLinks ." + hoverid).addClass("sel");
    }, function() {
        $(this).removeClass("hov");
        $(".mapLinks a").removeClass("sel");
    });

    // Linkkilistan hoverit
    $(".mapLinks a").hover(function() {
        var hoverid = $(this).attr("id");
        $("a#mark-" + hoverid).addClass("hov");
    }, function() {
        $("#map1fCover a, #map2fCover a").removeClass("hov");
    });


    /* flash */
	var params = {};
    var attributes = {};
    var flashvars = {};
    // EN or FIN
    if($("body").hasClass("en")) {	
        swfobject.embedSWF("http://" + document.domain + "/flash/europark_homepageflash_eng.swf", "flashplaceholder", "530", "302", "8.0.0", "" , flashvars, params, attributes);
	} else if($("body").hasClass("ru")) {	
        swfobject.embedSWF("http://" + document.domain + "/flash/europark_homepageflash_ru.swf", "flashplaceholder", "530", "302", "8.0.0", "" , flashvars, params, attributes);
    } else {
        // swfobject.embedSWF("http://" + document.domain + "/flash/Europark_p-city_banneri_vaihe4.swf", "flashplaceholder", "530", "302", "8.0.0", "" , flashvars, params, attributes);
        swfobject.embedSWF("http://" + document.domain + "/flash/europark_homepageflash.swf", "flashplaceholder", "530", "302", "8.0.0", "" , flashvars, params, attributes);
    }
	
	
	

});