﻿// equal heights of 2 columns
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if (thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

$(document).ready(function() {


    $('#PanelWarning').hide();

    // ensure the heights of both columns are the same
    equalHeight($(".dividerbar"));


    // on pageload see if we should scroll down
    var vis = $("#PanelResult:visible").attr("id");
    var vis2 = $("#PanelNoResult:visible").attr("id");

    if (vis != null || vis2 != null) {
        $('.pubright').show(); //changed to show() after logic change
        $.scrollTo('160px', 800);
    }

    //create the tabs
    $("#tabs").tabs({ spinner: 'Loading', cache: true, fx: { opacity: 'toggle', duration: 'fast'} }
                );

    $('#tabs').bind('tabsload', function(event, ui) {
        // Get URL of tab and send to GA
        var selected = $.data(ui.tab, 'load.tabs');
        pageTracker._trackPageview('/' + selected);
        equalHeight($(".eqh"));
        equalHeight($(".ui-tabs-panel"));
    });

    $('#tabs').bind('tabsshow', function(event, ui) {
        //change default color of Upgrade tab
        if ($('#ui-tabs-special').parent().hasClass("ui-state-default")) {
            $('#ui-tabs-special').addClass("ui-tabs-speciald");
        }
    });


    //load tabs from left column clicks
    var $options = $('#tabs').tabs();

    $('.dividerbar')
                    .click(function() { // bind click event to update the Tab
                        //get companyID + companyName
                        var $cid = document.getElementById('HiddenFieldCompanyIDDetails').value;
                        var $cname = document.getElementById('HiddenFieldCompanyName').value;

                        //set URLs of the tabs
                        $options.tabs('url', 0, 'company.aspx?cid=' + $cid);
                        $options.tabs('url', 1, 'employees.aspx?cid=' + $cid);
                        $options.tabs('url', 2, 'articles.aspx?cid=' + $cid);
                        $options.tabs('url', 3, 'map.aspx?cid=' + $cid);
                        $options.tabs('url', 4, 'upgrade.aspx?cid=' + $cid);

                        //if first tab then reload
                        var $sel = $options.tabs('option', 'selected');
                        if ($sel == 0) {
                            $options.tabs('load', 0);
                        }

                        //otherwise just activate first tab
                        $options.tabs('select', 0); // switch to 1st tab

                        //scroll up if too far down
                        $.scrollTo('160px', 800);

                        //change the meta tags for the Sharing to work better in Facebook
                        // First, get the array of meta-tag elements
                        // $("meta[name=keywords]").attr("content", "a,b,c,d");
                        metatags = document.getElementsByTagName("meta");

                        // Iterate through the array, listing them all
                        // Update only the Title meta tag

                        for (cnt = 0; cnt < metatags.length; cnt++) {

                            var name = metatags[cnt].getAttribute("name");
                            var content = metatags[cnt].getAttribute("content");

                            // List the original meta tag name=content
                            //alert(name + " = " + content + "");

                            // Update the Title meta tag
                            if (metatags[cnt].getAttribute("name") == "title") {
                                metatags[cnt].setAttribute("content", "Playback BluePages: " + $cname);
                            }
                            if (metatags[cnt].getAttribute("name") == "description") {
                                metatags[cnt].setAttribute("content", "Company listing for " + $cname);
                            }
                        }
                        return false;
                    })
                    .css({ backgroundPosition: "0 0" })
                    .mouseover(function() {
                        $(this).stop().animate({ backgroundPosition: "(0 -250px)" }, { duration: 500 })
                    })
		            .mouseout(function() {
		                $(this).stop().animate({ backgroundPosition: "(0 0)" }, { duration: 500 })
		            });


});


$(function() {

    //all hover and click logic for buttons
    $(".fg-button:not(.ui-state-disabled)")
		            .hover(
			            function() {
			                $(this).addClass("ui-state-hover");
			            },
			            function() {
			                $(this).removeClass("ui-state-hover");
			            }
		            )
		            .mousedown(function() {
		                $(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
		                if ($(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active')) { $(this).removeClass("ui-state-active"); }
		                else { $(this).addClass("ui-state-active"); }
		            })
		            .mouseup(function() {
		                if (!$(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button')) {
		                    $(this).removeClass("ui-state-active");
		                }
		            });
});


$(function() {

    $('#aboutbluepages').hide();

    // toggles the slickbox on clicking the noted link
    $('#aboutquestion').click(function() {
        $('#aboutbluepages').toggle(400);
        return false;
    });

});   

