$(function() {

    // App related scripting
    
    $(".rss_item:last").css({
        'borderBottom':'0',
        'marginBottom':'0'
    }); // Remove the border line from the last RSS item
    
    // Twitter manipulation
    
    $("#zone-footer3, .root-46 #zone-righttopinherit").find("h2").append('<img alt="Pertec Consulting Twitterissä" src="/res/default/img/pertec-twitter.png" id="pertec-twitter-icon" />'); // Add the Twotter logo to the header
    

    // Main column manipularion
    
    if ($("#tr-2-2")) {
        mainContentHasHeader = $("#tr-2-2").find("h2").html(); // Get the HTML of the first header in the main zone
    }    
    var columnsTogether = $("#row-2").find("td:nth-child(1)").width() + $("#row-2").find("td:nth-child(2)").width() +44; // Width of the first two columns minus the paddings of the header
    var headersHeight = $("#zone-_main").find("h2:first").height() + 18 + 18; // Header's height plus the header's padding, plus some spacing    
    
    if (mainContentHasHeader && mainContentHasHeader.length > 2) {
        $("#zone-_main").find("h2:first").css({
            'position':'absolute',
            'left':'0',
            'marginTop':'-'+headersHeight+'px',
            'width': columnsTogether+'px'
        }); // If found, make the header absolutely positioned, and stretch it to be as wide as the two columns combined       
    }
    
    $("#row-2").find("td:nth-child(1), td:nth-child(2)").css({
        'paddingTop':headersHeight+'px'
    }); // Add the header's height to the columns as a padding, so the content won't be positioned under the header

    
    // Front page video column manipulation
    
    var contentHasVideoClip = $("#zone-mainLeft").find(".token-Mediaclip"); // If a media clip exists
    
    if (contentHasVideoClip) {
        $("#zone-mainLeft").closest("td").css({
            'background':'none #fff',
            'paddingRight':'0px'
        }); // If there is a media clip in the zone, remove the padding from the closest column (eq. video clip's wrapper)
    }
    
    // Footer e-mail thingie
    
    var q = '.com';var m = 'c.fi';var z = 'fo@p';var d = 'se@';var x = 'in';var u = 'x.com';var y = 'erte';var iimeil = '<a href="mailto:'+x+z+y+m+'">'+x+z+y+m+'</a>';$("#copyright").append(iimeil);

    // Banner manipulation
    
    $(".token-Banner").find(".banner:last").after('<div class="hr-clear-fix"></div>');
    $(".token-Banner .banner:even").addClass("banner-pairless");
    
    // Top content text manipulation
    
    $(".contentFrame td p:last").css({'marginBottom':'0'});
    
    // Theme picture mouse hover effects    
    
    $(".pertec-triangle-link").hover( 
        function(){
    
            var posX = ($(this).width() / 2);
            
            var bubbleText = "";
            var fromBottom = "50";
            var fromLeft = "0";
            
            if ( $(this).attr("id") == "pertec-triangle-top" ) {
                if ( $("body").hasClass("root-46") ) {
                    bubbleText = "<li>Intelligent self leadership</li><li>Executive coaching</li><li>360 leadership coaching</li><li>ISL – self leadership web-service</li>";
                }
                else {    
                    bubbleText = "<li>&Auml;lyk&auml;s itsens&auml; johtaminen</li><li>Johdon coaching</li><li>360 johtajuus-coaching</li><li>ISL – Itsens&auml; johtamisen verkkopalvelu</li>";
                }      
                fromBottom = "250";
                fromLeft = "57";
            }
            
            if ( $(this).attr("id") == "pertec-triangle-left" ) {
                if ( $("body").hasClass("root-46") ) {
                    bubbleText = "<li>Intelligent organization</li><li>Defining and implementing strategy</li><li>Values and common way we work</li><li>Performance management</li><li>Managing change and renewal</li><li>Competence management</li><li>Management of work wellbeing</li>";
                }
                else {             
                    bubbleText = "<li>&Auml;lykkk&auml;&auml;n organisaation kehittäminen</li><li>Strategian kirkastaminen ja toteutus</li><li>Arvot ja yhtenäinen tapa toimia</li><li>Suorituksen johtaminen</li><li>Muutoksen ja uudistumisen johtaminen</li><li>Osaamisen johtaminen</li><li>Työhyvinvoinnin johtaminen</li>";
                }
            }
            
            if ( $(this).attr("id") == "pertec-triangle-right" ) {
                if ( $("body").hasClass("root-46") ) {
                    bubbleText = "<li>Intelligent leadership</li><li>Leading creativity and innovation</li><li>Coaching in sales and leadership</li><li>Leading diversity</li><li>Leading networks and collaboration</li><li>Management team unity and performance</li>";
                }
                else {             
                    bubbleText = "<li>&Auml;lyk&auml;s johtaminen</li><li>Luovuuden ja innovatiivisuuden johtaminen</li><li>Valmentava myynti ja johtaminen</li><li>Monimuotoisuuden johtaminen</li><li>Verkostoituminen ja yhteisty&ouml;</li><li>Johtoryhmien yhten&auml;isyys ja toimivuus</li>";
                }         
                fromLeft = "130";         
            }                
            
            if (bubbleText != "") {
                $(this).after('<div style="position: absolute; bottom: '+fromBottom+'px; left: '+fromLeft+'px; z-index: 80;" class="bubble-text"><ul class="bubble-list">'+ bubbleText +'</ul></div>');
            }    
            
        },
        function(){
            $(".bubble-text, .bubble-list").remove();
        });
        
    // Search field manipulation
    
        var searchTerm = "";
        if ($("body").hasClass("root-46")) {
            searchTerm = "Search our site";
        }
        else {
            searchTerm = "Hae sivuiltamme";
        }
    
		$('input.q')
			.attr('value', searchTerm)
			.css('font-style', 'italic')
			.focus(function() {
				if ( $(this).attr('value') == searchTerm ) {
					$(this)
						.attr('value', '')
						.css('font-style', 'normal');
				}
			})
			.blur(function() {
				if ( ! $(this).attr('value') ) {
					$(this)
						.attr('value', searchTerm)
						.css('font-style', 'italic');
				}
			});
            

});

