// dropdown menu
$(document).ready(function() {
    $('.Level0 li').hover(
	 function() { $(this).addClass('over'); },
	 function() { $(this).removeClass('over'); });
});
$(document).ready(function() {
    $('.Level0 li:last-child').hover(
	 function() { $(this).addClass('LastItemHover'); },
	 function() { $(this).removeClass('LastItemHover'); });
});

//$('UtilityNavigationControl ul li:first-child a span').addClass("NoBorderLeft");
$(document).ready(function() {
$('.UtilityNavigationControl ul li:not(:last-child)').append("|");
$('.FooterRight ul li:not(:last-child)').append("|");
});
$(document).ready(function() {
$('.PrimaryNavigationControlLeft .Level1 li:not(:last-child)').addClass("NavBorderNone");
$('.PrimaryNavigationControlRight .Level1 li:not(:last-child)').addClass("NavBorderNone");
});


/*
$(document).ready(function() {
$('.ByFolderNavigationControl .Level1 li:not(.Current)').hide();
$('.ByFolderNavigationControl li.CurrentItem li').show();
$('.ByFolderNavigationControl li.CurrentItem').siblings().show();

});
*/
/*
$(document).ready(function() {
$('.ByFolderNavigationControl .Level1 li:not(.Current)').hide();
//$('.ByFolderNavigationControl .Level2 li:not(.Current)').hide();
$('.ByFolderNavigationControl li.CurrentItem').show();
$('.ByFolderNavigationControl li.CurrentItem').siblings().show();
//$('.ByFolderNavigationControl .Level2 li').hide();
});
*/
$(document).ready(function() {
    $('.ByFolderNavigationControl .Level1 li:not(.Current)').hide();
    //$('.ByFolderNavigationControl .Level2 li:not(.Current)').hide();

    $('.ByFolderNavigationControl li.CurrentItem').show();
    $('.ByFolderNavigationControl li.CurrentItem').children().show();
    $('.ByFolderNavigationControl li.CurrentItem').children().children().show();
    $('.ByFolderNavigationControl li.CurrentItem').siblings().show();


    $('.ByFolderNavigationControl li.HasChildren:not(.Current)').addClass("TreeClose");
    $('.ByFolderNavigationControl li.HasChildren.Current').addClass("TreeOpen");
    $('.ByFolderNavigationControl li:not(.HasChildren)').addClass("Dot");
});

/*$(document).ready(function() {
$('.PrimaryNavigationControlRight ul li:last-child').over(
function() { $(this).addClass('LastItemHover'); },
function() { $(this).removeClass('LastItemHover'); });
});
*/

//login
$(document).ready(function() {
    $('.LoginLink').click(function() {
        $('.GlobalLoginControl').css('display', 'block');
        $('.DateControl').css('display', 'none');
        return false;
    });
    $('.CloseLogin').click(function() {
        $('.GlobalLoginControl').css('display', 'none');
        //$('.MyAccountLink').css('display', 'none');
    });
    $('.LoginButtonLink').click(function() {
        $('.GlobalLoginControl').css('display', 'none');
        //$('.LoginLink').css('display', 'none');
        //$('.LogoffLink').css('display', 'inline');
        $('.UserInfoControl').css('display', 'block');
        //$('.MyAccountLink').css('display', 'inline');
        $('.DateControl').css('display', 'block');
    });
    $('.LogoffLink').click(function() {
        //$('.LogoffLink').css('display', 'none');
        //$('.LoginLink').css('display', 'inline');
        $('.UserInfoControl').css('display', 'block');
        //$('.MyAccountLink').css('display', 'none');
        return false;
    });



    // accordion
    $(".MoreHead").click(function() {
        $(this).prev(".MoreBody").slideToggle(500);
        $(this).html("");
        //$(this).html("").html("<li class='less'><a href='#'>...less</a></li>");
        return false;
    });
    /*$(".less").click(function() {
    $(this).html("").html("<li class='MoreHead'><a href='#'>...more</a></li>");
    }*/
});
$(document).ready(function() {
    $(".GuidedNavigationControl p").click(function() {
        if (this.style.backgroundImage == "")
            $(this).css({ backgroundImage: "url(/_layouts/Aicpa.Org/Images/close.gif)" });
        else
            $(this).css({ backgroundImage: "" });
    });
});

//// What's Hot user control related jquery
$(document).ready(function() {
    var tabContainers = $('div.TabsContainer > div');
    tabContainers.hide().filter(':first').show();
    $('div.TabsContainer ul.tabs a').click(function() {
        tabContainers.hide();
        tabContainers.filter(this.hash).slideDown(1000);
        $('div.TabsContainer > .tabs > li.active')
            .removeClass('active');
        $(this).parent().addClass('active');
        return false;
    }).filter(':first').click();
});

// Text -resizing
$(document).ready(function() {
    // Decrease Font Size : 12px
    $(".small").bind('click', function() {
        $('#ContentBodyControl').addClass('small');
        $('#ContentBodyControl').removeClass('med');
        $('#ContentBodyControl').removeClass('big');
    });

    // medium Font Size : 14px
    $(".med").bind('click', function() {
        $('#ContentBodyControl').addClass('med');
        $('#ContentBodyControl').removeClass('small');
        $('#ContentBodyControl').removeClass('big');
    });

    // larger Font Size : 16px;
    $(".big").bind('click', function() {
        $('#ContentBodyControl').addClass('big');
        $('#ContentBodyControl').removeClass('med');
        $('#ContentBodyControl').removeClass('small');
    });
});


function pop(url) {
    newwindow = window.open(url, 'name', 'height=350,width=750');
    if (window.focus) { newwindow.focus() }
    return false;
}

$(document).ready(function() {
    $('.NewWindow').click(function() {
        $(this).attr('target', '_blank');
    });
});

/*
$(document).ready(function() {
$('#More').mouseover(function() {
$('.Details').css('display', 'block');
$('#More').addClass('ListOver');
});
$('#More').mouseout(function() {
$('.Details').css('display', 'none');
$('#More').addClass('ListNone');
});    
});
*/




// slide show
/*
$(document).ready(function() {
$('.Slideshow').cycle({
fx: 'fade',
prev: '#prev',
next: '#next',
prevNextClick: Prev,
pager: '#nav',
pagerEvent: 'click',
pagerClick: Pager
});
});
function Prev(curr, next, opts) {
var index = opts.currSlide;
$('.Slideshow').cycle('pause');
}
function Pager(zeroBasedSlideIndex, slideElement) {
$('.Slideshow').cycle('pause');
};
*/


$(document).ready(function() {
    $('.Slideshow').cycle({
        fx: 'fade',
        prev: '#prev',
        next: '#next',
        prevNextClick: Prev,
        pager: '#nav',
        pagerEvent: 'click',
        pagerClick: Pager,
        timeout: 5000
    });
});
function Prev(curr, next, opts) {
    var index = opts.currSlide;
    $('.Slideshow').cycle('pause');
}
function Pager(zeroBasedSlideIndex, slideElement) {
    $('.Slideshow').cycle('pause');
}

$(document).ready(function() {
//$('#pauseButton').click(function() {
//    $('.SlideshowSpotlight').cycle('pause');
//});
//$('#resumeButton').click(function() {
//    $('.SlideshowSpotlight').cycle('resume', true);
//});

$('#pause').click(function() { $('.SlideshowSpotlight').cycle('pause'); return false; });
$('#prev').click(function() { $('.SlideshowSpotlight').cycle('resume'); return false; });
$('#next').click(function() { $('.SlideshowSpotlight').cycle('resume'); return false; });
$('.SlideshowSpotlight').cycle({
        fx: 'fade',
        prev: '#prev',
        next: '#next',
        prevNextClick: Prev,
        pager: '#nav',
        //pagerEvent: 'mouseover',
        pagerClick: Pager,
       timeout: 5000
    });
});
function Prev(curr, next, opts) {
    var index = opts.currSlide;
    $('.SlideshowSpotlight').cycle('pause');
}

$(document).ready(function() {
    $('#pauseBtn').toggle(function() {

        $('.SlideshowSpotlight').cycle('pause');
        $(this).attr({ src: "~/_layouts/Aicpa.Org/Images/Pause-Button-Orange.jpg" });

    }, function() {

        $('.SlideshowSpotlight').cycle('resume', true);
        $(this).attr({ src: "~/_layouts/Aicpa.Org/Images/Pause-Button-White.jpg" });
    });
}); 
function Pager(zeroBasedSlideIndex, slideElement) {
    $('.SlideshowSpotlight').cycle('pause');
}

$(document).ready(function() {
$('.SlideshowJOA').cycle({
        fx: 'fade',
        prev: '#prev',
        next: '#next',
        prevNextClick: Prev,
        pager: '#nav',
        pagerEvent: 'click',
        pagerClick: Pager,
        timeout: 5000
    });
});
function Prev(curr, next, opts) {
    var index = opts.currSlide;
    $('.SlideshowJOA').cycle('pause');
}
function Pager(zeroBasedSlideIndex, slideElement) {
    $('.SlideshowJOA').cycle('pause');
}
// play-pause toggle button for JOA Spotlight
$(document).ready(function() {
    $('#pauseBtn').toggle(function() {

        $('.SlideshowJOA').cycle('pause');
        $(this).attr({ src: "~/_layouts/Aicpa.Org/Images/Pause-Button-Orange.jpg" });

    }, function() {

        $('.SlideshowJOA').cycle('resume', true);
        $(this).attr({ src: "~/_layouts/Aicpa.Org/Images/Pause-Button-White.jpg" });
    });
}); 

$(window).load(function() {
var tallest1 = 0;
    $('.SpotlightContents').each(function() {
    if ($(this).height() > tallest1)
        tallest1 = $(this).height();
    });
   // alert(tallest1);
    $('.SlideshowSpotlight').css('height', tallest1);
   // $('.SpotlightContents').height(tallest);
});

$(window).load(function() {
    var tallest2 = 0;
    $('.JournalOfAccountancyContents').each(function() {
        if ($(this).height() > tallest2)
            tallest2 = $(this).height();
    });
  //  alert("k" +tallest2);
    $('.SlideshowJOA').css('height', tallest2);
   // $('.SpotlightContents').height(tallest1);
});




/*
$(document).ready(function() {
$('.ByFolderNavigationControl .Level0 span').each(function() {
var txt1 = $(this).html();
if (txt1.length >= 30) {
//alert(txt1);
//alert(txt1.length);
var newtxt1 = txt1.substr(0, 30) + '...';
$(this).html(newtxt1);
}
});
$('.ByFolderNavigationControl .Level1 span').each(function() {
var txt2 = $(this).html();
if (txt2.length >= 25) {
var newtxt2 = txt2.substr(0, 25) + '...';
$(this).html(newtxt2);
}
});
// TODO: For next two blocks, need to merge them into one block.
//    $('h1 .PanelText:not(a)' || 'h1 .PanelText a').each(function(){
//        var txt3 = $(this).html();
//        if (txt3.length >= 30) {
//            //alert(txt3);
//            //alert(txt3.length);
//            var newtxt3 = txt3.substr(0, 30) + '...';
//            $(this).html(newtxt3);
//        }
//    });
//


}); */
$(document).ready(function() {
    var maxwidth = {


        'w675': 675,
        'w600': 600,
        'w550': 550,
        'w500': 500,
        'w450': 450,
        'w400': 400,
        'w300': 300,
        'w280': 280,
        'w250': 250,
        'w200': 200,
        'w150': 150,
        'w100': 100,
        'w50': 50,
        'w10': 10
    }

    $('div').find('img').each(function() {
        // alert('kannan');
        //$(this).css("width", "200px"); 
        var width = $(this).width();
        var height = $(this).height();
        // var v_max_width = maxwidth[$(this).parents().attr('resize')];
        var v_max_width = maxwidth[$(this).parents('[resize]').attr('resize')];
        if (width > v_max_width) {
            var ratio = (height / width);
            var new_width = v_max_width;
            var new_height = (new_width * ratio);
            $(this).height(new_height).width(new_width);
        }
    });

    $('div.AdBanner').find('img').each(function() {
    this.style.width = '';
    this.style.height = '';
     //   alert('ankit');
    });
//    $('div.ForeField').find('img').each(function() {
//        this.style.width = '';
//        this.style.height = '';
//        //   alert('champ');
//    });

});

function TakeSurvey() {
    var answer = confirm("Do you want to take a 2 minutes survey?")
    if (answer)
        window.location.href = "http://vovici.com/wsb.dll/s/4e5ag421ae";
    window.moveBy(0, 0);
}
//// block external links
//$(document).ready(function() {

//    $(function() {

//        var loc = (document.URL).substr(0, 21);
//        if (loc == 'http://edit.aicpa.org') {
//            // do nothing
//            $('.NewWindow').click(function() {
//                window.open($(this).attr('href'));
//                return false;
//            });
//        }
//        else if (loc == 'http://beta.aicpa.org') {
//            //alert('kannanmoss1');
//            //  alert(loc);
//            $("a").click(function() {
//                var currentLink = $(this).attr("href");
//                var currentLinkPre = $(this).attr("href").substr(0, 4);
//                var currentLinkPreBig = $(this).attr("href").substr(0, 11);
//                var redirectStr = "SendUserToIStore.aspx";

//                if (($(this).attr("href").indexOf("SendUsertoForefieldAdvisor.aspx") >= 0)
//                    || ($(this).attr("href").indexOf("SendUserToExternalSite.aspx") >= 0)
//                    || ($(this).attr("href").indexOf("sendusertoinstantforum.aspx") >= 0)
//                    || ($(this).attr("href").indexOf("edit.aicpa.org") >= 0)
//                    || ($(this).attr("href").indexOf("payaicz.aicpa.org") >= 0) 
//                    || ($(this).attr("href").indexOf("www.cpa2biz.com") >= 0)) {
//                    //alert('its ok');
//                    alert('External links and select AICPA links are not accessible from the Beta site. Please click OK to close this message and return to Beta testing.');
//                    return false;
//                }
//                else if (($(this).attr("href").indexOf("aicpa-sco.custhelp.com") >= 0) || ($(this).attr("href").indexOf("leopard.cpa2biz.com") >= 0) || ($(this).attr("href").indexOf("feedburner.com") >= 0) || ($(this).attr("href").indexOf("GetAccess") >= 0) || ($(this).attr("href").indexOf("Redirect/SendUserToIStore.aspx") >= 0)) {
//                    // do nothing      
//                }
//                //alert(currentLink);
//                // var newLink = "#";
//                /*if (currentLink.indexOf("SendUserToIStore.aspx") != -1) {
//                alert('it has');
//                alert('External links and select AICPA links are not accessible from the Beta site. Please click OK to close this message and return to Beta testing.');
//                return false;
//                }
//                else */
//                else if ((currentLinkPre == 'http') || (currentLinkPre == 'www.')) {
//                    if ((currentLink == 'http://vovici.com/wsb.dll/s/4e5ag421ae') || (currentLink == 'http://aicpa-sco.custhelp.com/') || (currentLink == 'http://get.adobe.com/reader/')) {
//                        //do nothing
//                    }
//                    else if ((currentLinkPreBig == 'http://edit') || (currentLinkPreBig == 'http://beta') || (currentLinkPreBig == 'http://stag') || (currentLinkPreBig == 'http://kann') || (currentLinkPreBig == 'http://chow')) {
//                        //do nothing
//                        //alert('edit');
//                    }
//                    else {
//                        // alert(newLink);
//                        //  extLink();
//                        //$(this).attr("href", newLink);
//                        alert('External links and select AICPA links are not accessible from the Beta site. Please click OK to close this message and return to Beta testing.');
//                        return false;
//                    }
//                }
//                else {
//                    //do nothing
//                }
//            });
//        }
//        else {
//            //  alert(loc);
//            $("a").click(function() {
//                var currentLink = $(this).attr("href");
//                var currentLinkPre = $(this).attr("href").substr(0, 4);
//                var currentLinkPreBig = $(this).attr("href").substr(0, 11);
//                var redirectStr = "SendUserToIStore.aspx";

//                if ($(this).attr("href").indexOf("sendusertoinstantforum.aspx") >= 0) {
//                    //alert('its ok');
//                    alert('External links and select AICPA links are not accessible from the Beta site. Please click OK to close this message and return to Beta testing.');
//                    return false;
//                }
//                else if (($(this).attr("href").indexOf("SendUserToIStore.aspx") >= 0) || ($(this).attr("href").indexOf("leopard.cpa2biz.com") >= 0) || ($(this).attr("href").indexOf("feedburner.com") >= 0) || ($(this).attr("href").indexOf("aicpa-sco.custhelp.com") >= 0) || ($(this).attr("href").indexOf("GetAccess") >= 0) || ($(this).attr("href").indexOf("www.cpa2biz.com") >= 0)) {
//                    // do nothing      
//                }
//                //alert(currentLink);
//                // var newLink = "#";
//                /*if (currentLink.indexOf("SendUserToIStore.aspx") != -1) {
//                alert('it has');
//                alert('External links and select AICPA links are not accessible from the Beta site. Please click OK to close this message and return to Beta testing.');
//                return false;
//                }
//                else */
//                else if ((currentLinkPre == 'http') || (currentLinkPre == 'www.')) {
//                    if ((currentLink == 'http://vovici.com/wsb.dll/s/4e5ag421ae') || (currentLink == 'http://aicpa-sco.custhelp.com/') || (currentLink == 'http://payaicz.aicpa.org/' || currentLink == 'http://get.adobe.com/reader/')) {
//                        //do nothing
//                    }
//                    else if ((currentLinkPreBig == 'http://edit') || (currentLinkPreBig == 'http://beta')
//                    || (currentLinkPreBig == 'http://stag') || (currentLinkPreBig == 'http://kann')
//                    || (currentLinkPreBig == 'http://pete') || (currentLinkPreBig == 'http://chow'
//                    || (currentLinkPreBig == 'http://sara') 
//                    )) {
//                        //do nothing
//                        //alert('edit');
//                    }
//                    else {
//                        // alert(newLink);
//                        //  extLink();
//                        //$(this).attr("href", newLink);
//                        alert('External links and select AICPA links are not accessible from the Beta site. Please click OK to close this message and return to Beta testing.');
//                        return false;
//                    }
//                }
//                else {
//                    //do nothing
//                }
//            });
//        }
//    });

//});

// not used as of now
function extLink() {
    newwindow = window.open('good.html', 'name', 'height=250,width=750');
    if (window.focus) { newwindow.focus() }
    return false;
}

// survey start
//ok = 1
//function openOnClose() {
//    if (ok) { Survey(); }
//}

function Survey() {
    var answer = confirm("Your feedback is important to us. Please take a moment to fill a short survey and let us know what you think about the new AICPA.org website. Please click OK to proceed to the survey. Click Cancel to skip the survey. Please make sure that pop-up blockers are disabled.");
    window.focus();
    if (answer) {
        /* window.location.href = "http://vovici.com/wsb.dll/s/4e5ag421ae";
        window.innerWidth = screen.width;
        window.innerHeight = screen.height;
        window.screenX = 0;
        window.screenY = 0;
        window.resizeTo(screen.width, screen.height);
        window.focus();*/

        var newWindow = window.open("http://vovici.com/wsb.dll/s/4e5ag421ae", '_blank', 'width=1010,height=700,left=0,top=0,screenX=0,screenY=0,scrollbars=yes');
        newWindow.focus();
        return false;
    }
}

/*var isMin = false;
function detectMinMax()
{
if(!isMin&&((window.screenLeft&&window.screenLeft==-32000)||(window.screenX&&window.screenX==-32000)))
{
isMin = true;
Survey();
}
}
setInterval('detectMinMax()', 500);
*/
/*
function initTimeOut() {
setTimeout('Survey()',1200000);
}
*/
/*window.onload = initTimeOut;*/
//window.onUnload = "openOnClose()";

function openSurvey() {
    //window.location.href = "http://vovici.com/wsb.dll/s/4e5ag421ae";
    // window.moveBy(0, 0);
    newwindow = window.open('good.html', 'name', 'height=700,width=960');
    window.moveBy(0, 0);
    if (window.focus) { newwindow.focus() }
    return false;
}

$(document).ready(function() {
    $(".IATabContent").hide();
    $("ul.Tabs li:first").addClass("active").show();
    $(".IATabContent:first").show();
    $("ul.Tabs li").click(function() {
        $("ul.Tabs li").removeClass("active");
        $(this).addClass("active");
        $(".IATabContent").hide();
        var activeTab = $(this).find("a").attr("href");
        $(activeTab).show();
        return false;
    });

});
//window.onUnload="openSurvey()";
//window.onbeforeunload=openSurvey;

// Survey End

/*
$(document).ready(function() {
$(function() {
var loc = (document.URL).substr(0, 21);
if (loc == 'http://beta.aicpa.org') {
//  var loc = (document.URL).substr(0, 11);
//  if (loc == 'http://kann') {
$("a").click(function() {
if (($(this).attr("href").indexOf("Redirect/SendUserToIStore.aspx") >= 0) || ($(this).attr("href").indexOf("edit.aicpa.org") >= 0) || ($(this).attr("href").indexOf("cpa2biz.com") >= 0)) {
alert('External links and select AICPA links are not accessible from the Beta site. Please click OK to close this message and return to Beta testing.');
return false;
}
});
}
});
});
*/
/* 
var loc = (document.URL).substr(0, 21);
if (loc != 'http://edit.aicpa.org') 
{
Survey();
}
*/
/*window.onload = locCheck;
function locCheck() {
alert('loc check');
var lock = (document.URL).substr(0, 17);
alert(lock);
if (lock != 'http://kannanmoss') {
alert('here');
Survey();
}
}
*/

/*
if(self.location==top.location)self.location="index.html";
*/

//window.onunload = function() { Survey(); }

function popupLoading() {
    window.open('/_LAYOUTS/SRI/popup.html', 'win4', 'width=400,height=300,top=350,left=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
}

$(document).ready(function() {
    $("#PopupL a").click(function() {
        if ($(this).attr("id") == 'SRI') {
            popupLoading();
        }
        else {
            // do nothing      
        }
    });
});



// FRC Popup 
//loading popup with jQuery magic!
var popupStatus = 0;

function setCookie()
{
var exdays=3650;
var value="YES";
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie="aicpa_FRC" + "=" + c_value;
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

function loadPopup(){

//document.cookie=
	//loads popup only if it is disabled
	if(popupStatus==0) 
	{
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}



