// Begin jQuery
$(document).ready(function () {

    /* png-fix ie6 */
    //$(document).pngFix(); 

    /*Hopefully removes flicker...*/
    if ($.browser.msie == true) {
        document.execCommand('BackgroundImageCache', false, true);
    }

    /*set height background*/
//    if ($(".columns").length) {

//        $(".columns>div").height($(".columns").height());
//    }



    //$('#idList li')
    ///*	.css( {opacity: '.6'}   )*/
    //	/*.mouseover(function(){
    //		})
    //	.mouseout(function(){
    //		$(this).stop().animate(
    //			{backgroundPosition:("0 0")}, 0)
    //		}) */
    //		.mouseover(function(){
    //		$(this).css(
    //		{backgroundPosition:("-10px 68px")}, 0)

    ///*		$(this).stop().animate(
    //			{opacity: 1}, 250)*/
    //		})
    //	.mouseout(function(){
    //			$(this).stop().animate(
    //			{backgroundPosition:("0 0")}, 0)
    //		/*$(this).stop().animate(
    //			{opacity: 0.6}, 500)*/
    //		})


    //Make list clickable

    // make the cursor over <li> element to be a pointer instead of default
    $('#idList li').hover(
      function () {
         // $(this).css("background-position", "0 -73px");
      },
      function () {
        // $(this).css("background-position", "0 0");
      }
    )
    // iterate through all <li> elements with CSS class = "clickable"
    // and bind onclick event to each of them
    .click(function () {
        // when user clicks this <li> element, redirect it to the page
        // to where the fist child <a> element points


        if ($('a', this).attr('href').toString().indexOf(document.domain.toString()) == -1) {

            if ($('a', this).attr('href').toString())
                window.open($('a', this).attr('href'));


        } else {

            if ($('a', this).attr('href').toString())
                window.location.href = $('a', this).attr('href');
        }

    });

    //Make menu clickable


    //    .click(function() {
    //        window.location.href = $('a', this).attr('href');
    //    });


    //Make menu hover effects
    /*
    $('.mainmenu a')
    .mouseover(function(){
    $(this).stop().animate(
    {color:"#eee",
    opacity: 1}, 250)
    })
    .mouseout(function(){
    $(this).stop().animate(
    {color:"#ccc",
    opacity: 1}, 250)
    })
    */
});

// Website dropdown scripts

function websiteDropDown() {
    $("#selectSiteDropDown").slideToggle(150);

}
function websiteDropDownSetTimer(timerValue) {
    document.onclick = websiteDropDownSlideUp;
    closeTimer = window.setTimeout(websiteDropDownSlideUp, timerValue);
}

function websiteDropDownCancelTimer() {
    if (typeof (window['closeTimer']) != "undefined") {
        document.onclick = "";
        window.clearTimeout(closeTimer);
        closeTimer = null;
    }
}

function websiteDropDownSlideUp() {
    document.onclick = "";
    $("#selectSiteDropDown").slideUp(150);
}

function calenderViewToggle(tableView) {
    var list = $("#calendarViewContainer>div");
    var table = $("#calendarViewContainer>table");
    var listbtn = $(".listviewbtn-class");
    var tablebtn = $(".tableviewbtn-class");
    var checkbox = $("#calendarViewContainer input[type=checkbox]");

    if (tableView) {
        $(checkbox).attr('checked', true);
        $(tablebtn).css("font-weight", "bold");
        $(listbtn).css("font-weight", "normal");
        $(list).hide();
        $(table).show();
    }
    else {
        $(checkbox).attr('checked', false);
        $(tablebtn).css("font-weight", "normal");
        $(listbtn).css("font-weight", "bold");
        $(table).hide();
        $(list).show();
    }
}

// END Website dropdown scripts

// Fields: Default-text

function searchField(searchField, focus) {
    if (focus) {
        if (searchField.value == searchField.defaultValue) {
            searchField.value = "";
        }
    }
    else if (!searchField.value.length) {
        searchField.value = searchField.defaultValue;
    }
}

function passField(field, focus) {
    if (focus) {
        if (field.value == field.defaultValue) {
            $(field).hide();
            $(".real-passfield").show();
            $(".real-passfield").focus();
        }
    }
    else if (!field.value.length) {
    $(".dummy-passfield").show();
    $(field).hide();
    }
}

// END: Fields: Default-text

// Calendarfilter
function chkBoxFilter(chkBox, filterValue){

//    if ($(chkBox).is(':checked'))
//        $("." + filterValue).show();
//    else
//        $("." + filterValue).hide();

    // First get all the checked inputs
    var checkedValues = [];

    $("#filter-container").find("input[type=checkbox][checked]").each(function() {
        checkedValues.push($(this).parents("span").attr("class"));
    });

    // Now get all the filterable items
    $(".calendarItemText").each(function() {
        var found = false;
        for (var i = 0; i < checkedValues.length; i++) {
            if ($(this).hasClass(checkedValues[i])) {
                found = true;
                break;
            }
        }
        if (found)
            $(this).show();
        else
            $(this).hide();
    });



}

function loadnewsletter(link, loadURL) {
    var loadContainer = $("#newsletter-container");

    $(loadContainer).empty();
    $(loadContainer).hide();
    
    var ajaxLoader = $(link).siblings(".ajax-loader");
    
    $(ajaxLoader).show();

    $(loadContainer).load(loadURL + " #emptyframework-content", function() {
        $(ajaxLoader).hide();
        $(loadContainer).show();

        //get the top offset of the target anchor
        var target_offset = $(loadContainer).offset();
        var target_top = target_offset.top;
	 
        //goto that anchor by setting the body scroll top to anchor top
        $('html, body').animate({scrollTop:target_top}, 500);
    });
        
    $(link).toggleClass("expanded");
}
