/**
 *
 *  Front End JavaScript
 *
 */

$(document).ready(function() {
    $(".gmaps-links a, .map-location-label, .community-links, #blog-link").attr("target", "_blank");
    var relativePositionFix = parseInt($("#wrapper").offset().left, 10);
    $(".pointer-label").mouseover(function(e) {
        var imgElm = "#" + $(this).attr("id") + "-img";
        $(imgElm).css({"display" : "block", "top" : (e.pageY + 10) + "px", "left" : (e.pageX - relativePositionFix + 10) + "px"});
    });
    
    $(".pointer-label").mouseout(function() {
        var imgElm = "#" + $(this).attr("id") + "-img";
        $(imgElm).css({"display" : "none"});
    });
    
    $(".pointer-label").mousemove(function(e) {
        var imgElm = "#" + $(this).attr("id") + "-img";
        $(imgElm).css({"top" : (e.pageY + 10) + "px", "left" : (e.pageX - relativePositionFix + 10) + "px"});
    });
    
    //position menu on top of column
    if($(".stories-main .left-column").outerHeight() > $(".stories-main .right-column").outerHeight()) {
        var columnChange = $(".stories-main .left-column").height() - $(".stories-main .right-column").height();
        var elmPadding = columnChange + parseInt($("#career-stories-menu").css("paddingTop"), 10) - 5;
        $("#career-stories-menu").css("marginTop", elmPadding);
    }
    
    //add target=_blank attribute to news and press-release attachment links
    $(".news-file, .press-release-file").attr("target", "_blank");
    
    /*
    $("#request-quote-btn").click(function() {
        $("#overlay-wrapper").css("display", "block");
        return false;
    });
    */
    $("#overlay-wrapper").click(function(e) {
        if($(e.target).attr("id") == $(this).attr("id")) {
            $(this).css("display", "none");
        }
    })
    
    $(".close-overlay-btn").click(function() {
        $("#overlay-wrapper").css("display", "none");
        return false;
    });
    
    //add flash banner
    if( $("#flash-presentation").attr("id") ) {
        var rewriteFix = $("#rewrite_fix_js").text();
        var langFix = $("#lang_fix_js").text();
        var embedHTML = AC_FL_RunContent(
            'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
            'width', '960',
            'height', '297',
            'src', rewriteFix + 'assets/interface/banner' + langFix,
            'quality', 'high',
            'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
            'align', 'middle',
            'play', 'true',
            'loop', 'true',
            'scale', 'showall',
            'wmode', 'window',
            'devicefont', 'false',
            'id', 'banner',
            'bgcolor', '#ffffff',
            'name', 'banner',
            'menu', 'true',
            'allowFullScreen', 'false',
            'allowScriptAccess','sameDomain',
            'movie', rewriteFix + 'assets/interface/banner_' + langFix,
            'salign', ''
        );
        $("#flash-presentation").append(embedHTML);
    }
    
    //add table row for specific fields
    $(".add-more-btn").click(function() {
        var tableTR = $(this).parent().parent();
        var newRow = "<tr>" + tableTR.parent().find(".copied-row").html() + "</tr>";
        $(newRow).insertBefore(tableTR);
        return false;
    });
    
    //job listing buttons
    $(".hide-job-details-btn").click(function() {
        $(this).parent().css("display", "none");
        $(this).parent().parent().css("color", "#8B8B8B");
        $(this).parent().prev().css("display", "block");
        return false;
    });
    
    $(".job-read-more").click(function() {
        $(this).parent().css("display", "none");
        $(this).parent().parent().css("color", "#4C4C4C");
        $(this).parent().next().css("display", "block");
        return false;
    });
    
    $("#date-jf").datepicker({dateFormat: 'yy-mm-dd'});
});
