$(document).ready(function () {
    initWebkitTarget();
    initButtons();
    //initToolTips();
    SetPageHiddenValueForPaging();
    //initTable();
    //disableButtonAfterClick();
    initAccordion();
    initUserName();
	$('#col2, #col2Wide').fileIcon();
});

function initWebkitTarget() {
    if ($.browser.webkit) {
        $("#wrapper").addClass("webkit");
    }
}

function initButtons() {
    $("input[type=button], input[type=submit], button").button();
    $("button.btnUser, a.btnUser").button({ icons: { primary: "ui-icon-person"} });
    $("button.btnPage, a.btnPage").button({ icons: { primary: "ui-icon-document"} });
    $("button.btnEdit, a.btnEdit").button({ icons: { primary: "ui-icon-pencil"} });
    $("button.btnSave, a.btnSave").button({ icons: { primary: "ui-icon-disk"} });
}

function SetPageHiddenValueForPaging() {




    $(".page-number a").bind("click", function () {


        var pagingNoId = $(this).closest(".pager").prev("input:hidden");  //$(e.target).parent().children("input:text");
      
        if (pagingNoId != null) {

            var text = this.innerHTML;


            switch (text) {

                case "First":

                    pagingNoId.val("1");
                    break;

                case "Next":

                    pagingNoId.val(parseInt(pagingNoId.val()) + 1);
                    break;

                case "Previous":

                    pagingNoId.val(parseInt(pagingNoId.val()) - 1);
                    break;

                case "Last":
                    pagingNoId.val("-1");

                    break;

                default:

                    pagingNoId.val(text);
                    break;

            }
        }

    });
}

function initToolTips() {
    /*$("[title]").each(function() {
    var tooltip;
    $(this).hover(function() {
    tooltip = $.pnotify({
    pnotify_text: $(this).attr("title"),
    pnotify_type: 'notice',
    pnotify_hide: false,
    pnotify_history: false
    });
    },
    function() {
    tooltip.pnotify_remove();
    });
    $(this).mousemove(function(event) {
    tooltip.css({'top': event.clientY+12, 'left': event.clientX+12});
    });
    });*/

    $("[title]").tipsy({ fade: true });

}

function initAccordion() {
    $('.accordion div.featureListSummary').hide();
    $('.accordion').find('div.featureListTitleWrap:first').addClass('selected');
    $('.accordion').find('div.featureListSummary:first').show();
    $('.accordion div.featureListTitleWrap').click(
	function () {
	    // for the h3 in #accordian that has been clicked do this:
	    var checkElement = $(this).next(); //create a new variable called checkElement which is equal to the element after this h3

	    if ((checkElement.is('div')) && (checkElement.is(':visible'))) { // if checkElement is a div AND checkElement is visible then do:
	        return false;
	    }
	    if ((checkElement.is('div')) && (!checkElement.is(':visible'))) { // if checkElement is a div AND checkElement is not visible then do:
	        $('.accordion div.featureListTitleWrap').removeClass('selected'); //find all h2s in #accordian and remove the class 'selected'
	        $(this).closest('.accordion').find('div.featureListSummary:visible').slideUp('normal'); //find all visible divs in accordian and slide up
	        $(this).addClass('selected'); //add the class 'selected' to this h2
	        checkElement.slideDown('normal'); // slidedown checkElement
	        return false;
	    }
	}
	);
}


function initUserName() {
    $("#ctl00_header1_LoginView1_signin_usernamebx").focusin(function () {
        if ($(this).val() == 'Username') {
            $(this).val("");
        }
    });
    $("#ctl00_header1_LoginView1_signin_usernamebx").focusout(function () {
        if ($(this).val() == '') {
            $(this).val("Username");
        }
    });
    $("#ctl00_header1_LoginView1_signin_passwordbx").css("background", "url(/skins/images/passwordback.gif) no-repeat #FFF left");
    $("#ctl00_header1_LoginView1_signin_passwordbx").focusin(function () {
        if ($(this).val() == '') {
            $(this).css("background", "none #FFF");
        }
    });
    $("#ctl00_header1_LoginView1_signin_passwordbx").focusout(function () {
        if ($(this).val() == '') {
            $(this).css("background", "url(/skins/images/passwordback.gif) no-repeat #FFF left");
        }
    });
}




