﻿/// <reference path="jquery-1.4.2.min.js"/>

var pageTracker;
var defaultFile = "default.aspx";

// google analytics tracking code
jQuery(document).ready(function ($) {


    //    if ($('.checkMembershipOption').checked)
    //        $('#ViewOptionMembershipTable').css('display', 'block');

    $('#MembershipFees td').click(function () {
        $('#MembershipFees td').removeClass('highLight');
        //rel="val:450,label:government,chamber:member"
        var rel = $(this).attr('rel');
        var arr = new Array();
        arr = rel.split(',');
        var val = arr[0].split(':')[1];
        var label = arr[1].split(':')[1];
        var chamber = arr[2].split(':')[1];
        // alert("val is " + val + " label is " + label + " chamber is " + chamber);

        $(".memberFee").val(rel);
        $(this).addClass('highLight');
    });

//    $("#RegisterButton").click(function () {
//        $('#RegisterButton').css("background-image", "url(/AppSkin/register-here-click.jpg)");  
//    },  function { 
//       // $('#RegisterButton')css("background-image", "url(/AppSkin/register-here-click.jpg)");  
//    });
   


    /*   var gaTrackCode = "UA-";//Need new Account
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");

    jQuery.getScript(gaJsHost + "google-analytics.com/ga.js", function() {
    try {
    pageTracker = _gat._getTracker(gaTrackCode);
    pageTracker._trackPageview();
    } catch (err) { }
    });

    AddTrackPageAnalytics(); 
    AddDocumentAnalytics();
    */

});

function Initializers() {
    InitModalImages();
   WireMenu();
//    Signup('a.signup');
//    if ($("#HomePage").length == 0)
//        CurrentMenu();


}



/*
* Site-functions 
*/
function removeSpace(wordIn) {
 var str = wordIn;
 if (str != 0)
    return str.replace("%20", " ");
 else return "";
}
 
function urlParam(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (!results) { return 0; }
	return results[1] || 0;
}

(function($) {   
    $.fn.stripHtml = function() {   
        var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;   
        this.each(function() {   
           $(this).html(   
                $(this).html().replace(regexp, "")
            );   
        });   
        return $(this);   
    }
})(jQuery);

/*
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 */
$.fn.equalHeights = function(px) {
    $(this).each(function() {
        var currentTallest = 0;
        $(this).children(".adjust").each(function(i) {
            if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
        });
        //if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
        // for ie6, set height since min-height isn't supported
        if ($.browser.msie && $.browser.version == 6.0) { $(this).children(".adjust").css({ 'height': currentTallest }); }
        $(this).children(".adjust").css({ 'min-height': currentTallest });
    });
    return this;
};

$.fn.equalWidths = function(px) {
    $(this).each(function() {
        var currentWidest = 0;
        $(this).children().each(function(i) {
            //alert($(this).width());
            if ($(this).width() > currentWidest) { currentWidest = $(this).width(); }
        });
        //if (!px || !Number.prototype.pxToEm) currentWidest = currentWidest.pxToEm(); //use ems unless px is specified
        // for ie6, set height since min-height isn't supported
        if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({ 'width': currentWidest }); }
        $(this).children().css({ 'min-width': currentWidest });
    });
    return this;
};

function Signup(target) {
    $(target).fancybox({
        'frameWidth': 425,
        'frameHeight': 275,
        'centerOnScroll': true,
        'hideOnContentClick': false,
        'zoomOpacity': true,
        'zoomSpeedIn': 600,
        'zoomSpeedOut': 500
    });
    //'type': 'iframe'toptions="group = links, type = iframe, effect = fade, width = 600, height = 475, overlayClose = 1, layout = quicklook" 
}



function CheckSearchResults()
{
   var fileTypes = ['doc', 'xls', 'docx', 'xlsx', 'pdf', 'ppt', 'zip'];

    $('a.gs-title').each(function() {
        var $a = $(this);
        var href = $a.attr('href');

        if (href != null) {
            var hrefArray = href.split('.');
            var extension = hrefArray[href.length - 1];

            if ($.inArray(extension, fileTypes) != -1) {
                $a.hover(function() {
                    $a.attr("target", "_blank");
                });
            }
        }
    });
}

function SendPage(target) {
    $(target).fancybox({
        'frameWidth': 340,
        'frameHeight': 320,
        'centerOnScroll': true,
        'hideOnContentClick': false,
        'zoomOpacity': true,
        'overlayOpacity':.15,
        'zoomSpeedIn': 600,
        'zoomSpeedOut': 500
    });
}

function InitModalImages() {
    $('a.modalImage').fancybox({
        'centerOnScroll': true,
        'hideOnContentClick': false,
        'zoomOpacity': true,
        'zoomSpeedIn': 600,
        'zoomSpeedOut': 500,
        'easingIn': 'easeOutBack',
        'easingOut': 'easeInBack'
    });

    $('div.ImageGallery a').fancybox({
        'centerOnScroll': true,
        'hideOnContentClick': false,
        'zoomOpacity': true,
        'zoomSpeedIn': 600,
        'zoomSpeedOut': 500,
        'easingIn': 'easeOutBack',
        'easingOut': 'easeInBack'
    });
    
}

function WireMenu() {
  // $('#MainMenu li:first a:first').parent('li').css("border-left", "none");

//    var countLi = $('#MainMenu').children('li').size();
//    var containerWidth = $('#container').width();
//    var menuWidth = $('#MainMenu').width();
//    if ((menuWidth - containerWidth) > 0) {
//        var paddingSides = $('#MainMenu li a').css('paddingLeft').replace("px", "");
//        var diff = ((menuWidth - containerWidth) / (countLi * 2));
//        $('#MainMenu li a').not('#MainMenu ul li a').css('padding-left', paddingSides - diff);
//        $('#MainMenu li a').not('#MainMenu ul li a').css('paddingRight', paddingSides - diff);
//       // alert(" padding width is " + paddingSides + " with a diff of " + diff);
//        //alert(" padding width is " + (menuWidth - containerWidth) + " menu width " + menuWidth);
//    }
   
   $('li.main').removeClass('nojs');
   $('#MainMenu li.main').hover(
        function () {
            //alert("Mother");
            //        //$('ul li a', this).equalWidths();
            $('ul', this).slideDown({ speed: 'fast', easing: 'easeOutBack' });
            $(this).siblings('li').removeClass('current');
            $(this).addClass('current');
        },
        function () {
           // $('ul', this).hide(ClearCurrent(this));
            $('ul', this).slideUp({ speed: 'fast', easing: 'easeOutExpo' }, ClearCurrent(this));
        }
    );
      
      /*  $('#TopMenu li.main').hover(
    function () {
    $('ul', this).show();
    $(this).siblings('li').removeClass('current');
    $(this).addClass('current');
    // $(this).children('a').not('.subNavigation a').css('border-top', '3px solid green');
    },
    function () {
    $('ul', this).hide(ClearCurrent(this));
    }
    );     
    */ 
}
    
function ClearCurrent(target) {
    $(target).removeClass('current');
}

function CurrentMenu() {
    var newpath = window.location.href.replace("http://" + window.location.host + "/", "");
    var tempPath = newpath.split("/", 1);
    var thisPath = tempPath[0].toLowerCase(); //tempPath is an array still

    // path is all in lowercase
    var path = "/" + thisPath + "/";

////    $("#PageMenu li a").each(function (index) {
////        //alert($(this).attr('href').toLowerCase() + " path is " + path + page);
////        if ($(this).attr('href').toLowerCase() == path + page) {
////            $(this).addClass("active");
////        }
////    });

    $("li.main a").not(".SubNavigation a").each(function (index) {
        //alert($(this).attr('href').toLowerCase() );
        if ($(this).attr('href').toLowerCase() == path) {
            $(this).parent('li').addClass("active");
        }
    });
}
    
function PngFix() {
    $(function($) { $('.png').pngfix(); });
}

function AddTrackPageAnalytics() {
    $('a').each(function() {
        var $a = $(this);
        var href = $a.attr('href');

        // see if the link is external
        if (href != null && (href.match(/^http/)) && (!href.match(document.domain))) {

            // if so, add the GA tracking code
            $a.click(function() {
                pageTracker._trackPageview('/outbound/' + href);
            });
        }
    });
}

function AddDocumentAnalytics() {
    var fileTypes = ['doc', 'xls', 'docx', 'xlsx', 'pdf', 'ppt', 'zip'];

    $('a').each(function() {
        var $a = $(this);
        var href = $a.attr('href');

        if (href != null) {
            var hrefArray = href.split('.');
            var extension = hrefArray[href.length - 1];

            if ($.inArray(extension, fileTypes) != -1) {
                $a.click(function() {
                    // get the post title if there is one
                    // and add it to the string for tracking
                    pageTracker._trackPageview('/documents/' + href);
                   // $a.attr("target", "_blank");
                });
            }
        }
    });
}

jQuery.preloadImages = function() {
    for (var i = 0; i < arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}

function getQueryAnchorVar(str) {
    if ("undefined" == typeof (str))
        str = location.href;
    return (str.replace(/.+[\/]([^\/]+)$/, '$1'))
}

function checkTextSize() {
    var textSize = readCookie('textSize');
    if (textSize) {
        switchTextSize(textSize);

        switch (textSize) {
            case "large":
                $('#EnlargeText').attr('rel', 'default');
                $('#EnlargeText').text('Smaller Text');
                break;
            case "default":
                $('#EnlargeText').attr('rel', 'large');
                $('#EnlargeText').text('Enlarge Text');
        }
    }
}

// font switching features
function inkit() {
    var str = $('#EnlargeText').attr('rel');
    
    switchTextSize(str);
    createCookie('textSize', str, 365);
    
    switch (str) {
        case "large":
            $('#EnlargeText').attr('rel', 'default');
            $('#EnlargeText').text('Smaller Text');
            break;
        case "default":
            $('#EnlargeText').attr('rel', 'large');
            $('#EnlargeText').text('Enlarge Text');
    }
}

function switchTextSize(styleName) {
    var fileref = document.createElement('link');
    fileref.setAttribute('rel', 'stylesheet');
    fileref.setAttribute('type', 'text/css');
    fileref.setAttribute('href', '/AppStyle/text-size-' + styleName + '.css');
    document.getElementsByTagName('head')[0].appendChild(fileref);
}

function car_itemVisibleInCallback(carousel, item, i, state, evt) {
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, car_itemList.length);
    carousel.add(i, car_getItemHTML(car_itemList[idx - 1]));
};

function car_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
};

/**
* Item html creation helper.
*/
function car_getItemHTML(item) {
    var html = '<li>';
    html += '<img class="banner" src="/AppSkin/Banners' + item.img + '" alt="' + item.img.replace("-", " ").replace(".jpg", "") + '" />';
    html += '<div class="wave"></div>';
    html += '<img class="text" src="/AppSkin/Banners' + item.img.replace(".jpg", ".png") + '" alt="' + item.img.replace("-", " ").replace(".jpg", "") + '" />';
    html += '</li>';
    return html; //'<img src="' + item.img + '" width="75" height="75" alt="' + item.text + '" />';
};

function carouselStart() {
    $('#Carousel').jcarousel({
        scroll: 1,
        auto: 10,
        animation: 'normal',
        wrap: 'circular',
        itemVisibleInCallback: { onBeforeAnimation: car_itemVisibleInCallback },
        itemVisibleOutCallback: { onAfterAnimation: car_itemVisibleOutCallback }
    });
}

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
function eraseCookie(name) {
    createCookie(name, "", -1);
}
// cookie functions

// Calendar Functions
function CalRollOver() {
    $('.dat').each(function () {
        $(this).mouseenter(function () {
            //alert($(this).children('.calView').height());
            var height = $(this).children('.calView').height();
            $(this).children('.calView').css({ 'display': 'block', 'marginLeft': '-14px', 'marginTop': '-' + (height + 34) + 'px' })
        });
        $(this).mouseleave(function () {
            $(this).children('.calView').css({ 'display': 'none' })
        });
    });
}
