﻿// CURRENT URL
var currentUrl = window.location.href.toString();

// CURRENTLY DISPLAYED LANGUAGE
var currentLanguage = "";

function checkLanguage() {
    if ($(".CurrentLanguage").text() == "en") {currentLanguage = "English";}
    else { currentLanguage = "Portuguese"; }
}


function addLinkInfo(){
    $("span.LinkInfo").each(function() {
        $(this).wrap('<span class="LinkInfoWrapper"></span>');
        var linkInfoText = $(this).text();
        var linkInfoImageCode = "";
        linkInfoImageCode += '<img class="LinkInfoImage" src="/imagens/estrutura/about.png" alt="?" title="" />';
        $(this).after(linkInfoImageCode);
    });
    $("img.LinkInfoImage").bind("mouseenter", function() {
        $(this).prev().stop(true, true); 
        $(this).prev().fadeIn("fast");
    });
    $("img.LinkInfoImage").bind("mouseleave", function() {
        $(this).prev().stop(true, true);
        $(this).prev().fadeOut("fast");
    });
}

function displayPhotoViewer() {
    if ($("div#PhotoViewer").length) {
        if (currentLanguage = "English") {
            var photoViewerDefaultImageName = "photo-window-default-en.png";
        }
        else {
            var photoViewerDefaultImageName = "photo-window-default-pt.png";
        }        
        $("div#PhotoViewer img").each(function() {
            $(this).css("height", "45px").css("width", "auto");

            $(this).wrap("<div class='ThumbnailWrapper'></div>");
       

        });
            $("div#PhotoViewer").append("<div class='Clear'></div>");
            $("div#PhotoViewer").after("<div id='PhotoWindow'><img src='/imagens/estrutura/" + photoViewerDefaultImageName + "' alt='' /></div>");
            $("div#PhotoWindow").after("<div class='Clear'></div>");
        }
        $("div.ThumbnailWrapper").each(function() {
            var bigImage = $("div#PhotoWindow img");
            var smallImage = $(this).find("img");
            $(this).bind("click", function() {
                $(this).stop(true, true);
                $(bigImage).stop(true, true);
                $(this).fadeOut("fast", function() {
                $(this).fadeIn("fast");
                });
                bigImage.fadeOut("fast", function() {
                    var clickedImageSrc = smallImage.attr("src");
                    bigImage.attr("src", clickedImageSrc);
                    bigImage.fadeIn("fast");
                });

            });

        });

}


// WRITE OUT DCA E-MAILS (SPAMMER PROTECTION)
function writeDcaEmail() {
    $("span.DcaEmail").each(function() {
        var emailName = $(this).text();
        var emailLinkCode = "";
        emailLinkCode += "<a href='mailto:";
        emailLinkCode += emailName;
        emailLinkCode += "@dcabr.org.br'>";
        emailLinkCode += emailName + "@dcabr.org.br</a>";
        $(this).html(emailLinkCode).show();
    });
}
// ADD ROUNDED SHAPES TO CERTAIN CONTAINERS
function addRoundedShapes() {
    $("div.ContactForm").each(function() {
        $(this).wrap('<div class="ContactFormWrapper"></div>');
        $(this).parent().prepend('<div class="RoundedAreaHeader"><div></div></div>');
        $(this).parent().append('<div class="RoundedAreaFooter"><div></div></div>');
    });
    $("div.RoundedArea").each(function() {
        $(this).wrap('<div class="RoundedAreaWrapper"></div>');
        $(this).parent().prepend('<div class="RoundedAreaHeader"><div></div></div>');
        $(this).parent().append('<div class="RoundedAreaFooter"><div></div></div>');
        $(this).find("h2").css("margin", "0");
        $(this).find("p:last").css("margin-bottom", "2px");
    });
}

// WRITE THE COURSE LIST TABLE
function writeCourseList() {
    if ($("div.CourseList").length) {

        if (currentLanguage == "English") {
            var courseListDateText = "Date";
            var courseListCourseText = "Course";
            var courseListLocalText = "Place";
        }
        else {
            var courseListDateText = "Data";
            var courseListCourseText = "Curso";
            var courseListLocalText = "Local";
        }

        $("div.CourseList").each(function() {
            var courseListCode = "";
            courseListCode += "<h3 class='CourseListHeader'>" + $(this).find("h3").text() + "</h3>";
            //THE BASIC CODE FOR THE COURSE TABLE
            courseListCode += "<table class='CourseList'>";
            courseListCode += "<tr class='Header'>";
            courseListCode += "<td class='CourseDate'>" + courseListDateText + "</td>";
            courseListCode += "<td class='CourseName'>" + courseListCourseText + "</td>";
            courseListCode += "<td class='CourseLocal'>" + courseListLocalText + "</td>";
            courseListCode += "<td class='CourseSignup'></td>";
            courseListCode += "</tr>";
            courseListCode += "</table>";
            $(this).after(courseListCode);

            // SHOW COURSE TABLE BY DEFAULT IF INDICATED
            if ($(this).hasClass("CourseListOpen") == true) {
                $(this).next().addClass("CourseListHeaderOpen");
                $(this).next().next().addClass("CourseListOpen");
            }
        });

        // FIND ALL COURSES AND INSERT THEM INTO THE TABLE
        $("div.CourseList div.Course").each(function() {
            var courseName = $(this).find("a.CourseName");
            var courseDate = $(this).find("span.CourseDate");
            var courseLocal = $(this).find("span.CourseLocal");
            var courseSignup = $(this).find("a.CourseSignup");

            var courseCode = "";
            courseCode += "<tr>";

            //DATE CELL
            courseCode += "<td class='CourseDate'>" + $(courseDate).html() + "</td>";

            // NAME CELL
            courseCode += "<td class='CourseName'>";
            if ($(courseName).attr("href") != "") {
                courseCode += "<a href='" + $(courseName).attr("href") + "'>" + $(courseName).html() + "</a>";
            } else {
                courseCode += $(courseName).html();
            }
            courseCode += "</td>";

            //LOCAL CELL
            courseCode += "<td class='CourseLocal'>" + $(courseLocal).html() + "</td>";

            // SIGNUP CELL
            courseCode += "<td class='CourseSignup'>";
            if ($(courseSignup).attr("href") != "") {
                courseCode += "<a href='" + $(courseSignup).attr("href") + "'>" + $(courseSignup).html() + "</a>";
            }
            courseCode += "</td>";
            courseCode += "</tr>";

            $(this).parent().next().next().append(courseCode);
        });
        $("table.CourseList").each(function() {
            $(this).find("tr:even").addClass("AlternateRow");
            $(this).find("tr:last").addClass("LastRow");

        });
    }
    // THE ANIMATION FOR THE COURSE LIST HEADER
    $("h3.CourseListHeader").bind("click", function() {
        $(this).toggleClass("CourseListHeaderOpen");
        $(this).next().slideToggle("fast");
    });
}

/*
function writeCourseList() {
    if ($("div.CourseList").length) {
        
		if (currentLanguage == "English") {
			var courseListDateText = "Date";
			var courseListCourseText = "Course";
		}
		else {
			var courseListDateText = "Data";
			var courseListCourseText = "Curso";
		}
		
		$("div.CourseList").each(function() {
			var courseListCode = "";
	        courseListCode += "<table class='CourseList'>";
    	    courseListCode += "<tr class='Header'>";
	        courseListCode += "<td class='CourseDate'>" + courseListDateText + "</td>";
    	    courseListCode += "<td class='CourseName'>" + courseListCourseText + "</td>";
        	courseListCode += "<td class='CourseSignup'></td>";
	        courseListCode += "</tr>";
	        courseListCode += "</table>";
        	$("div.CourseList").after(courseListCode);
		});

        // FIND ALL EVENTS AND INSERT THEM INTO THE TABLE
        $("div.CourseList div.Course").each(function() {
            var courseName = $(this).find("a.CourseName");
            var courseDate = $(this).find("span.CourseDate");
            var courseSignup = $(this).find("a.CourseSignup");

            var courseCode = "";
            courseCode += "<tr>";

            //DATE CELL
            courseCode += "<td class='CourseDate'>" + $(courseDate).html() + "</td>";

            // NAME CELL
            courseCode += "<td class='CourseName'>";
            if ($(courseName).attr("href") != "") {
                courseCode += "<a href='" + $(courseName).attr("href") + "'>" + $(courseName).html() + "</a>";
            } else {
                courseCode += $(courseName).html();
            }
            courseCode += "</td>";

            // SIGNUP CELL
            courseCode += "<td class='CourseSignup'>";
            if ($(courseSignup).attr("href") != "") {
                courseCode += "<a href='" + $(courseSignup).attr("href") + "'>" + $(courseSignup).html() + "</a>";
            }
            courseCode += "</td>";

            courseCode += "</tr>";

            $("table.CourseList").append(courseCode);
        });
        $("table.CourseList tr:even").addClass("AlternateRow");
        $("table.CourseList tr:last").addClass("LastRow");
    }
}
*/

// WRITE THE EVENT LIST TABLE
function writeEventList() {
    if ($("div.EventList").length) {

        if (currentLanguage == "English") {
            var eventListDateText = "Date";
            var eventListEventText = "Event";
            var eventListLocalText = "Local";
        }
        else {
            var eventListDateText = "Data";
            var eventListEventText = "Evento";
            var eventListLocalText = "Local";
        }


        $("div.EventList").each(function() {
            var eventListCode = "";
            eventListCode += "<h2 class='EventListHeader'>" + $(this).find("h2").text() + "</h2>";
            //THE BASIC CODE FOR THE EVENT TABLE
            eventListCode += "<table class='EventList'>";
            eventListCode += "<tr class='Header'>";
            eventListCode += "<td class='EventDate'>" + eventListDateText + "</td>";
            eventListCode += "<td class='EventName'>" + eventListEventText + "</td>";
            eventListCode += "<td class='EventLocal'>" + eventListLocalText + "</td>";
            eventListCode += "<td class='EventSignup'></td>";
            eventListCode += "</tr>";
            eventListCode += "</table>";
            $(this).after(eventListCode);
            
            // SHOW EVENT TABLE BY DEFAULT IF INDICATED
            if ($(this).hasClass("EventListOpen") == true) {
                $(this).next().addClass("EventListHeaderOpen");
                $(this).next().next().addClass("EventListOpen");
            }
        });
        
        // FIND ALL EVENTS AND INSERT THEM INTO THE TABLE
        $("div.EventList div.Event").each(function() {
            var eventName = $(this).find("a.EventName");
            var eventDate = $(this).find("span.EventDate");
            var eventLocal = $(this).find("span.EventLocal");
            var eventSignup = $(this).find("a.EventSignup");

            var eventCode = "";
            eventCode += "<tr>";

            //DATE CELL
            eventCode += "<td class='EventDate'>" + $(eventDate).html() + "</td>";

            // NAME CELL
            eventCode += "<td class='EventName'>";
            if ($(eventName).attr("href") != "") {
                eventCode += "<a href='" + $(eventName).attr("href") + "'>" + $(eventName).html() + "</a>";
            } else {
                eventCode += $(eventName).html();
            }
            eventCode += "</td>";

            //DATE LOCAL
            eventCode += "<td class='EventLocal'>" + $(eventLocal).html() + "</td>";

            // SIGNUP CELL
            eventCode += "<td class='EventSignup'>";
            if ($(eventSignup).attr("href") != "") {
                eventCode += "<a href='" + $(eventSignup).attr("href") + "'>" + $(eventSignup).html() + "</a>";
            }
            eventCode += "</td>";
            eventCode += "</tr>";

            $(this).parent().next().next().append(eventCode);
        });
        $("table.EventList").each(function() {
            $(this).find("tr:even").addClass("AlternateRow");
            $(this).find("tr:last").addClass("LastRow");

        });
    }
    // THE ANIMATION FOR THE EVENT LIST HEADER
    $("h2.EventListHeader").bind("click", function() {
        $(this).toggleClass("EventListHeaderOpen");
        $(this).next().slideToggle("fast");
    });
}


// MAKE SPACES IN LONG LINK LISTS
function insertLinkListSpaces() {
    if ($("ul.LinkList").length) {
        $("ul.LinkList").each(function() {
            if ($(this).children().size() > 5) {
                $(this).find("li:eq(3)").append('<div class="LinkListSpacer"></div>');
                $(this).find("li:eq(7)").append('<div class="LinkListSpacer"></div>');
                $(this).find("li:eq(11)").append('<div class="LinkListSpacer"></div>');
                $(this).find("li:eq(15)").append('<div class="LinkListSpacer"></div>');
                $(this).find("li:eq(19)").append('<div class="LinkListSpacer"></div>');
                $(this).find("li:eq(23)").append('<div class="LinkListSpacer"></div>');                                                                
            }
        });
    }

}

// TRAINING ITEM SHOW CLICKED
function showTrainingItem(item) {
    var itemId = "#" + item
    if ($(itemId).hasClass("VisibleItem") == false) {
        if ($(".VisibleItem").html() != null) {
            $(".VisibleItem").slideUp("fast", function() {
                $("#TrainingItemContainer div").removeClass("VisibleItem");
                $(itemId).addClass("VisibleItem");
                $(itemId).slideDown("fast");
            });
        }
        else {
            $(itemId).addClass("VisibleItem");
            $(itemId).slideDown("fast");
        }
    }
}


function showLinkedTrainingItem() {
    // IF THERE IS A LINKED TRAINING ITEM
    if (window.location.href.match("#mostre_") == "#mostre_") {
        // STRIP URL TO GET TO TRAINING ITEM
        var hashPosition = currentUrl.indexOf("#");
        var linkedTrainingItem = currentUrl.substr(hashPosition);
        linkedTrainingItem = linkedTrainingItem.replace("#mostre_", "");
        // ONLY TRY TO SHOW TRAINING ITEM IF IT EXISTS
        if ($("#" + linkedTrainingItem).length) {
            showTrainingItem(linkedTrainingItem);
        }
    }
}


// COORDINATOR SHOW CLICKED
function showCoordinator(item) {
    var clickedLink = "#link_" + item;
    $("div#CoordinatorLinks a").removeClass("Clicked");
    //alert(clickedLink);
    $(clickedLink).addClass("Clicked");
    var itemId = "#" + item
    if ($(itemId).hasClass("VisibleItem") == false) {
        if ($(".VisibleItem").html() != null) {
            $(".VisibleItem").slideUp("fast", function() {
                $("#CoordinatorContainer div").removeClass("VisibleItem");
                $(itemId).addClass("VisibleItem");
                $(itemId).slideDown("fast");
            });
        }
        else {
            $(itemId).addClass("VisibleItem");
            $(itemId).slideDown("fast");
        }
    }
}


function showLinkedCoordinator() {
    // IF THERE IS A LINKED COORDINATOR
    if (window.location.href.match("#mostre_") == "#mostre_") {
        // STRIP URL TO GET TO COORDINATOR 
        var hashPosition = currentUrl.indexOf("#");
        var linkedCoordinator = currentUrl.substr(hashPosition);
        linkedCoordinator = linkedCoordinator.replace("#mostre_", "");
        // ONLY TRY TO SHOW COORDINATOR IF IT EXISTS
        if ($("#" + linkedCoordinator).length) {
            showCoordinator(linkedCoordinator);
        }
    }
}



// EVENT ITEM SHOW CLICKED
function showEventItem(item) {
    var itemId = "#" + item
    if ($(itemId).hasClass("VisibleItem") == false) {
        if ($(".VisibleItem").html() != null) {
            $(".VisibleItem").slideUp("fast", function() {
                $("#EventContainer div").removeClass("VisibleItem");
                $(itemId).addClass("VisibleItem");
                $(itemId).slideDown("fast");
            });
        }
        else {
            $(itemId).addClass("VisibleItem");
            $(itemId).slideDown("fast");
        }
    }
}


// COURSE ITEM SHOW CLICKED
function showCourseItem(item) {
    var itemId = "#" + item
    if ($(itemId).hasClass("VisibleItem") == false) {
        if ($(".VisibleItem").html() != null) {
            $(".VisibleItem").slideUp("fast", function() {
                $("#CourseContainer div").removeClass("VisibleItem");
                $(itemId).addClass("VisibleItem");
                $(itemId).slideDown("fast");
            });
        }
        else {
            $(itemId).addClass("VisibleItem");
            $(itemId).slideDown("fast");
        }
    }
}


// PRINT TRAINING ITEM (POPUP)
function printTrainingItem(id) {
    $(id).parent().find(".TrainingItemPrint").hide(); // HIDE PRINT BUTTON
    $(id).parent().find(".TrainingItemPdf").hide(); // HIDE PDF BUTTON

    var trainingContent = $(id).parent().html();
    var pageTitle = $(id).parent().find("h2").text();
    
    var standardContent = '<img src="/imagens/estrutura/logo-print.gif" alt="" style="width: 400px; height: 100px;"><br><br>';
    //standardContent += '<p><strong>Texto padrão para imprimir um curso. Lorem ipsum dolor sit amet.</strong><br><br></p>';

    newwin = window.open('', 'printwin', 'left=100,top=100,width=500,height=400,scrollbars=yes');
    newwin.document.write('<HTML>\n<HEAD>\n');
    newwin.document.write('<TITLE>DCA-BR - ' + pageTitle + ' </TITLE>\n');
    newwin.document.write('<link type="text/css" rel="stylesheet" href="/css/dca-br-print.css">\n');
    newwin.document.write('<script>\n');
    newwin.document.write('function chkstate(){\n');
    newwin.document.write('if(document.readyState=="complete"){\n');
    newwin.document.write('window.close()\n');
    newwin.document.write('}\n');
    newwin.document.write('else{\n');
    newwin.document.write('setTimeout("chkstate()",2000)\n');
    newwin.document.write('}\n');
    newwin.document.write('}\n');
    newwin.document.write('function print_win(){\n');
    newwin.document.write('window.print();\n');
    newwin.document.write('chkstate();\n');
    newwin.document.write('}\n');
    newwin.document.write('<\/script>\n');
    newwin.document.write('</HEAD>\n');
    newwin.document.write('<BODY onload="print_win()">\n');
    newwin.document.write(standardContent);
    newwin.document.write(trainingContent);
    newwin.document.write('</BODY>\n');
    newwin.document.write('</HTML>\n');
    newwin.document.close();

    $(id).parent().find(".TrainingItemPrint").show(); // RESTORE PRINT BUTTON
    $(id).parent().find(".TrainingItemPdf").show(); // RESTORE PDF BUTTON
}




// PRINT EVENT (POPUP)
function printEvent() {

    var eventContent = $("#EventContainer").html();
    var pageTitle = document.title;

    var standardContent = '<img src="/imagens/estrutura/logo-print.gif" alt="" style="width: 400px; height: 100px;"><br><br>';
    //standardContent += '<p><strong>Texto padrão para imprimir um curso. Lorem ipsum dolor sit amet.</strong><br><br></p>';

    newwin = window.open('', 'printwin', 'left=100,top=100,width=500,height=400,scrollbars=yes');
    newwin.document.write('<HTML>\n<HEAD>\n');
    newwin.document.write('<TITLE>DCA-BR - ' + pageTitle + ' </TITLE>\n');
    newwin.document.write('<link type="text/css" rel="stylesheet" href="/css/dca-br-print.css">\n');
    newwin.document.write('<script>\n');
    newwin.document.write('function chkstate(){\n');
    newwin.document.write('if(document.readyState=="complete"){\n');
    newwin.document.write('window.close()\n');
    newwin.document.write('}\n');
    newwin.document.write('else{\n');
    newwin.document.write('setTimeout("chkstate()",2000)\n');
    newwin.document.write('}\n');
    newwin.document.write('}\n');
    newwin.document.write('function print_win(){\n');
    newwin.document.write('window.print();\n');
    newwin.document.write('chkstate();\n');
    newwin.document.write('}\n');
    newwin.document.write('<\/script>\n');
    newwin.document.write('</HEAD>\n');
    newwin.document.write('<BODY onload="print_win()">\n');
    newwin.document.write(standardContent);
    newwin.document.write(eventContent);
    newwin.document.write('</BODY>\n');
    newwin.document.write('</HTML>\n');
    newwin.document.close();
}

// PRINT EVENT (POPUP)
function printCourse() {

    var courseContent = $("#CourseContainer").html();
    var pageTitle = document.title;

    var standardContent = '<img src="/imagens/estrutura/logo-print.gif" alt="" style="width: 400px; height: 100px;"><br><br>';
    //standardContent += '<p><strong>Texto padrão para imprimir um curso. Lorem ipsum dolor sit amet.</strong><br><br></p>';

    newwin = window.open('', 'printwin', 'left=100,top=100,width=500,height=400,scrollbars=yes');
    newwin.document.write('<HTML>\n<HEAD>\n');
    newwin.document.write('<TITLE>DCA-BR - ' + pageTitle + ' </TITLE>\n');
    newwin.document.write('<link type="text/css" rel="stylesheet" href="/css/dca-br-print.css">\n');
    newwin.document.write('<script>\n');
    newwin.document.write('function chkstate(){\n');
    newwin.document.write('if(document.readyState=="complete"){\n');
    newwin.document.write('window.close()\n');
    newwin.document.write('}\n');
    newwin.document.write('else{\n');
    newwin.document.write('setTimeout("chkstate()",2000)\n');
    newwin.document.write('}\n');
    newwin.document.write('}\n');
    newwin.document.write('function print_win(){\n');
    newwin.document.write('window.print();\n');
    newwin.document.write('chkstate();\n');
    newwin.document.write('}\n');
    newwin.document.write('<\/script>\n');
    newwin.document.write('</HEAD>\n');
    newwin.document.write('<BODY onload="print_win()">\n');
    newwin.document.write(standardContent);
    newwin.document.write(courseContent);
    newwin.document.write('</BODY>\n');
    newwin.document.write('</HTML>\n');
    newwin.document.close();
}

function animateNode(id) {
    //    alert($(id).parent().html());
    var nodeToAnimate = $(id).parent().find("div.LvlWrapper").eq(0);
    if (nodeToAnimate.css("display") == "none") {
        nodeToAnimate.slideDown("fast", function() {
            nodeToAnimate.css("zoom","1"); // IE7 FIX TO TRIGGER HASLAYOUT
        });
        $(id).addClass("NodeOpen");
    }
    else {
        nodeToAnimate.slideUp("fast");
        $(id).removeClass("NodeOpen");
    }
}

function initiateLeftMenu(id) {

    // RENDER THE NODE CONTROLS
    
    //RENDER THE CONTAINER DIVS FOR ALL LINKS
    $("div.Lvl4Wrapper > a.LinkName").wrap('<div class="Lvl4"></div>');
    $("div.Lvl3Wrapper > a.LinkName").each(function() {
        if ($(this).next().hasClass("Lvl4Wrapper") == true) {
            var lvl4Container = $(this).next().prev().andSelf();
            $(lvl4Container).wrapAll("<div class='Lvl3'></div>");
        }
        else {
            $(this).wrap("<div class='Lvl3'></div>");
        }
    });
    $("div.Lvl2Wrapper > a.LinkName").each(function() {
        if ($(this).next().hasClass("Lvl3Wrapper") == true) {
            var lvl3Container = $(this).next().prev().andSelf();
            $(lvl3Container).wrapAll("<div class='Lvl2'></div>");
        }
        else {
            $(this).wrap("<div class='Lvl2'></div>");
        }
    });
    $("div.Lvl1Wrapper > a.LinkName").each(function() {
        if ($(this).next().hasClass("Lvl2Wrapper") == true) {
            var lvl2Container = $(this).next().prev().andSelf();
            $(lvl2Container).wrapAll("<div class='Lvl1'></div>");
        }
        else {
            $(this).wrap("<div class='Lvl1'></div>");
        }
    });

    // ADD NODE CONTROLS TO ALL LINKS
    $("a.LinkName").before('<a class="NodeControl"><img alt="" src="/imagens/estrutura/trans.gif" /></a>');
    
    // ADD GENERIC WRAPPER CLASS TO ALL WRAPPERS
    $(".Lvl1Wrapper, .Lvl2Wrapper, .Lvl3Wrapper, .Lvl4Wrapper").addClass("LvlWrapper");

    // CHECK WHICH LINK IS CURRENTLY ACTIVE, OPEN TREE AND MARK LINK AS CURRENT
    // IF THERE IS A SEPARATE LINK DEFINED ON THE PAGE, USE IT FIRST
    var currentNavUrl = "";
    if ($("a.LeftMenuIndicator").parent().html() != null) {
        currentNavUrl = $("a.LeftMenuIndicator").attr("href").toString();
    }
    // OTHERWISE USE THE CURRENT URL
    else {
        currentNavUrl = currentUrl;
    }
    currentNavUrl = currentNavUrl.replace("http://localhost:10001","");
    currentNavUrl = currentNavUrl.replace("http://dca-br.lowpinginfo.com", "");
    //currentNavUrl = currentNavUrl.replace("http://www.dcabr.org.br/novo", "");
    currentNavUrl = currentNavUrl.replace("http://www.dcabr.org.br", "");

    // CLEAR HASH TAGS AND QUERY STRINGS
    currentNavUrl = currentNavUrl.replace(/\?.*/, "");
    currentNavUrl = currentNavUrl.replace(/#.*/, "");    
        
    $("a.LinkName").each(function() {
        var linkUrl = $(this).attr("href");

        if (linkUrl == currentNavUrl) {

            if ($(this).parent().hasClass("Lvl4")) {
                $(this).parent().parent().show();
                $(this).parent().parent().parent().parent().show();
                $(this).parent().parent().parent().parent().parent().parent().show();
                $(this).addClass("ActiveLeftLink");
            }

            else if ($(this).parent().hasClass("Lvl3")) {
                $(this).parent().parent().show();
                $(this).parent().parent().parent().parent().show();
                $(this).addClass("ActiveLeftLink");
            }
            else if ($(this).parent().hasClass("Lvl2")) {
                $(this).parent().parent().show();
                $(this).addClass("ActiveLeftLink");
            }
            else if ($(this).parent().hasClass("Lvl1")) {
                $(this).addClass("ActiveLeftLink");
            }

            var connectedWrapper = $(this).parent().find("div.LvlWrapper").eq(0);
            if ($(connectedWrapper).html() != null) {
                connectedWrapper.show();
            }
        }
    });

    // ADD LANGUAGE QUERYSTRING FOR ALL ENGLISH LINKS
    $("div.MenuContentEnglish a.LinkName").each(function() {
        orgHref = $(this).attr("href");
        $(this).attr("href",orgHref + "?lang=en");
    });

    // HIDE NODE CONTROLS FOR LINKS THAT DO NOT HAVE CHILD NODES
    $(".NodeControl").each(function() {
        var connectedWrapper = $(this).parent().find("div.LvlWrapper").eq(0);
        if ($(connectedWrapper).html() == null) {
            $(this).hide();
        }
        else if ($(connectedWrapper).css("display") == "block") {
            $(this).addClass("NodeOpen");
        }
    });

    // BIND CLICK ACTION 
    $("a.NodeControl").bind("click", function() {
        animateNode(this);
    });
    
}

function initiateSubLinkContainer() {
    if ($("div.SubLinkContainer").parent().html() != null) {
        var subNodeContainer = $("a.ActiveLeftLink").parent().find("div.LvlWrapper").eq(0);
        if (subNodeContainer.html() != null) {
            $("div.SubLinkContainer").html('<ul class="LinkList"></ul>');
            subNodeContainer.children().children("a.LinkName").each(function() {
                var subLinkCode = "";
                subLinkCode += '<li>';
                subLinkCode += '<a href="';
                subLinkCode += $(this).attr("href");
                subLinkCode += '">';
                subLinkCode += $(this).text();
                subLinkCode += '</a>';
                subLinkCode += '</li>';
                $("div.SubLinkContainer ul").append(subLinkCode);
            });
        }
    }
}

// CODE FOR TRAINING ITEM PAGE
function initiateTrainingItems() {
    if ($("div.TrainingItem").html() != null) {

        if (currentLanguage == "English") {
            var printThisCourseText = "Print this course";
            var printIconAlt = "Print";            
            var downloadCourseCatalog = "Download the course catalog in PDF format";
            var catalogUrl = "/download/treinamento/dca-br_cursos_2010_web.pdf";
        }
        else {
            var printThisCourseText = "Imprimir este curso";
            var printIconAlt = "Imprimir";
            var downloadCourseCatalog = "Baixar o catálogo de cursos em PDF";
            var catalogUrl = "/download/treinamento/dca-br_cursos_2010_web.pdf";
        }        


        // ADD PRINT & PDF LINKS TO TRAINING ITEMS
        var trainingItemPrintPdfCode = "";
        trainingItemPrintPdfCode += '<a class="TrainingItemPrint" title="' + printThisCourseText + '" href="#" onclick="printTrainingItem(this);">';
        trainingItemPrintPdfCode += '<img src="/imagens/estrutura/printer.png" alt="' + printIconAlt + '"/>';
        trainingItemPrintPdfCode += '</a>';
        trainingItemPrintPdfCode += '<a class="TrainingItemPdf" title="' + downloadCourseCatalog + '" ';
        trainingItemPrintPdfCode += 'href="' + catalogUrl + '" target="_blank">'; //#TRAININGITEMCODE FOR DIRECT LINK
        trainingItemPrintPdfCode += '<img src="/imagens/estrutura/pdf-icon.png" alt="PDF"/>';
        trainingItemPrintPdfCode += '</a>';

        $("div.TrainingItem").each(function() {
            var thisTrainingItemId = $(this).attr("id");
            var thisTrainingItemPrintPdfCode = trainingItemPrintPdfCode.replace("TRAININGITEMCODE", thisTrainingItemId)
            $(this).prepend(thisTrainingItemPrintPdfCode);
        });

        // CREATE THE TRAINING ITEM LINK LIST
        $("#TrainingItemContainer").before('<div id="TrainingItemLinks"></div>');
        $("#TrainingItemLinks").html('<ul class="LinkList"></ul>');
        $("div.TrainingItem").each(function() {
            var trainingItemId = $(this).attr("id");
            var trainingItemName = $(this).find("h2").text();
            var trainingItemLinkCode = '';
            trainingItemLinkCode += '<li>';
            trainingItemLinkCode += '<a href="javascript:showTrainingItem(\'';
            trainingItemLinkCode += trainingItemId;
            trainingItemLinkCode += '\');">';
            trainingItemLinkCode += trainingItemName;
            trainingItemLinkCode += '</a></li>';
            $("#TrainingItemLinks ul").append(trainingItemLinkCode);
        });

        // ADD HEADER AND FOOTER TO TRAINING ITEM CONTAINER
        $("#TrainingItemContainer").before('<div class="TrainingItemContainerHeader"></div>');
        $("#TrainingItemContainer").after('<div class="TrainingItemContainerFooter"></div>');

        // DEFAULT TRAINING PAGE ITEM TEXT
        var defaultTrainingMessage = "";

        if (currentLanguage == "English") {
            defaultTrainingMessage = "Click an item above for detailed information.";
        }
        else {
            defaultTrainingMessage = "Clique em um item acima para visualizá-lo.";
        }
        $("#TrainingItemContainer").prepend('<div class="VisibleItem">' + defaultTrainingMessage + '</div>');

        // CHECK FOR LINKED TRAINING ITEMS
        showLinkedTrainingItem();


    }
}


// TRANSFORM COORDINATORS INTO LINKS
function coordinatorTransformToLink() {
    $("span.Coordinator").each(function() {
        var coordinatorId = coordinatorNameTransform($(this).text());
        //alert(coordinatorId);
        if (currentLanguage == "English") {
            var coordinatorPopupText = "Click for coordinator resume";
        }
        else {
            var coordinatorPopupText = "Veja o currículo resumido do coordenador";
        }
        var coordinatorLinkCode = "<a href='/produtos-e-servicos/treinamento/coordenadores-e-instrutores.aspx#mostre_" + coordinatorId + "'></a>";
        $(this).wrapInner(coordinatorLinkCode);
        $(this).append("<span class='LinkInfo'>" + coordinatorPopupText + "</span><span style='padding-left: 20px'></span>");

    });
}


// FUNCTION FOR TRANSFORMING COORDINATOR NAMES INTO COORDINATOR ID:S
function coordinatorNameTransform(coordinatorName) {
    var transformedText = coordinatorName.toLowerCase();
    transformedText = transformedText.replace(/[^a-z]*\n[^a-z]*/g, ""); //DELETE ALL NEWLINES AND SPACES AFTER AND BEFORE THEM
    transformedText = transformedText.replace(/  /g, " "); //DELETE ACCIDENTAL DOUBLE SPACES IN NAME
    transformedText = transformedText.replace(/ /g, "-");
    transformedText = transformedText.replace(/ç/g, "c");
    transformedText = transformedText.replace(/ã|á|à/g, "a");
    transformedText = transformedText.replace(/é|è/g, "e");
    transformedText = transformedText.replace(/í/g, "i");
    return transformedText;
}

// CODE FOR COORDINATORS PAGE
function initiateCoordinators() {
    coordinatorTransformToLink();

    if ($("div.Coordinator").html() != null) {

        // CREATE THE COORDINATORS LINK LIST
        $("#CoordinatorContainer").before('<div id="CoordinatorLinks"></div>');
        $("div.Coordinator").each(function() {
            var coordinatorId = $(this).attr("id");
            var coordinatorName = $(this).find("h2").text();
            var coordinatorLinkCode = '';
            coordinatorLinkCode += '<a id="link_';
            coordinatorLinkCode += coordinatorId;            
            coordinatorLinkCode += '" href="javascript:showCoordinator(\'';
            coordinatorLinkCode += coordinatorId;
            coordinatorLinkCode += '\');">';
            coordinatorLinkCode += coordinatorName;
            coordinatorLinkCode += '</a>';
            $("#CoordinatorLinks").append(coordinatorLinkCode);
        });
        
        // DIVIDE LINKS INTO TWO GROUPS
        var numberOfCoordinators = $("#CoordinatorContainer").children().length;
        var numberOfCoordinatorsInFirstColumn = Math.round(numberOfCoordinators / 2);
        var coordinatorDividerString = "#CoordinatorLinks a:gt(" + (numberOfCoordinatorsInFirstColumn-1) + ")";
        $(coordinatorDividerString).wrapAll("<div id='CoordinatorSecondColumn'></div>");
        $("#CoordinatorLinks > a").wrapAll("<div id='CoordinatorFirstColumn'></div>");
        $("#CoordinatorLinks a").after("<br />");

        // SET LEFT COLUMN WIDTH
        $("#CoordinatorFirstColumn").width($("#CoordinatorFirstColumn").width() + 25);

        // ADD HEADER AND FOOTER TO COORDINATORS CONTAINER
        $("#CoordinatorContainer").before('<div class="CoordinatorContainerHeader"></div>');
        $("#CoordinatorContainer").after('<div class="CoordinatorContainerFooter"></div>');
        $("#CoordinatorLinks").append('<div class="Clear"></div>');


        // DEFAULT COORDINATOR ITEM TEXT
        var defaultCoordinatorMessage = "";

        if (currentLanguage == "English") {
            defaultCoordinatorMessage = "Click an item above for detailed information.";
        }
        else {
            defaultCoordinatorMessage = "Clique em um coordenador acima.";
        }
        $("#CoordinatorContainer").prepend('<div class="VisibleItem">' + defaultCoordinatorMessage + '</div>');


        // CHECK FOR LINKED COORDINATORS
        showLinkedCoordinator();
    }
}

function initiateBylawPage() {
    $(".BylawChapterHeader").bind("click", function() {
        $(this).toggleClass("BylawChapterHeaderOpen");
        $(this).next().slideToggle("fast");
    });
}

function initiatePublicationPage() {
    $(".PublicationWrapper").before("<div style='height: 15px;'></div>");
    $(".PublicationHeader").bind("click", function() {
        $(this).toggleClass("PublicationHeaderOpen");
        $(this).next().slideToggle("fast");
    });
}

function initiateEventPage() {
    // CODE FOR EVENTS PAGES
    if ($("div.EventItem").html() != null) {

        if (currentLanguage == "English") {
            var printThisEventText = "Print this event";
            var printIconAlt = "Print";
        }
        else {
            var printThisEventText = "Imprimir este evento";
            var printIconAlt = "Imprimir";
        }   


        // CREATE THE EVENT ITEMS LINK LIST
        $("#EventContainer").before('<div id="EventItemLinks"></div>');
        $("#EventItemLinks").html('<ul class="LinkList"></ul>');
        $("div.EventItem").each(function() {
            var eventItemId = $(this).attr("id");
            var eventItemName = $(this).find("h2").text();
            var eventItemLinkCode = '';
            eventItemLinkCode += '<li>';
            eventItemLinkCode += '<a href="javascript:showEventItem(\'';
            eventItemLinkCode += eventItemId;
            eventItemLinkCode += '\');">';
            eventItemLinkCode += eventItemName;
            eventItemLinkCode += '</a></li>';
            $("#EventItemLinks ul").append(eventItemLinkCode);
        });

        // ADD PRINT LINKS TO EVENTS
        if (currentUrl.toLowerCase().match("eventos-realizados") != "eventos-realizados") {
            var eventPrintCode = "";
            eventPrintCode += '<a class="EventPrint" title="' + printThisEventText + '" href="#" onclick="printEvent();">';
            eventPrintCode += '<img src="/imagens/estrutura/printer_small.png" alt="' + printIconAlt + '"/>' + printThisEventText;
            eventPrintCode += '</a>';
            $("div#EventItemLinks").prepend(eventPrintCode);
        }
        // ADD HEADER AND FOOTER TO TRAINING ITEM CONTAINER
        $("#EventContainer").before('<div class="EventContainerHeader"></div>');
        $("#EventContainer").after('<div class="EventContainerFooter"></div>');

        // SET FIRST EVENTITEM AS VISIBLE
        $("div.EventItem:eq(0)").addClass("VisibleItem");
        $("div.EventItem:eq(0)").show();
    }
}

function initiateUpComingCoursePage() {
    // CODE FOR UPCOMING COURSES
    if ($("div.CourseItem").html() != null) {

        // CREATE THE EVENT ITEMS LINK LIST
        $("#CourseContainer").before('<div id="CourseItemLinks"></div>');
        $("#CourseItemLinks").html('<ul class="LinkList"></ul>');
        $("div.CourseItem").each(function() {
            var courseItemId = $(this).attr("id");
            var courseItemName = $(this).find("h2").text();
            var courseItemLinkCode = '';
            courseItemLinkCode += '<li>';
            courseItemLinkCode += '<a href="javascript:showCourseItem(\'';
            courseItemLinkCode += courseItemId;
            courseItemLinkCode += '\');">';
            courseItemLinkCode += courseItemName;
            courseItemLinkCode += '</a></li>';
            $("#CourseItemLinks ul").append(courseItemLinkCode);
        });

        // ADD PRINT LINKS TO EVENTS
        var coursePrintCode = "";
        coursePrintCode += '<a class="CoursePrint" title="Imprimir este curso" href="#" onclick="printCourse();">';
        coursePrintCode += '<img src="/imagens/estrutura/printer_small.png" alt="Imprimir"/>Imprimir este curso';
        coursePrintCode += '</a>';
        $("div#CourseItemLinks").prepend(coursePrintCode);

        // ADD HEADER AND FOOTER TO TRAINING ITEM CONTAINER
        $("#CourseContainer").before('<div class="CourseContainerHeader"></div>');
        $("#CourseContainer").after('<div class="CourseContainerFooter"></div>');

        // SET FIRST EVENTITEM AS VISIBLE
        $("div.CourseItem:eq(0)").addClass("VisibleItem");
        $("div.CourseItem:eq(0)").show();
    }
}

//INFO LOCAL EVENTO
function localeventoInfo() {
    $("span.localevento").each(function() {
        if (currentLanguage == "English") {
            var localeventoPopupText = "...";
        }
        else {
            var localeventoPopupText = "O NOVOTEL oferece tarifa especial de hospedagem para os participantes do evento.<br />Entre em contato com o setor de reservas: (12) 4009-7800 - h0472-sb2@accor.com.br";
        }
        $(this).append("<span class='LinkInfo'>" + localeventoPopupText + "</span><span style='padding-left: 20px'></span>");

    });
}


// WRITE THE NEWS LIST TABLE
function writeNewsList() {
    if ($("div.NewsList").length) {

        if (currentLanguage == "English") {
            var newsListDateText = "Date";
            var newsListNewsText = "News";
        }
        else {
            var newsListDateText = "Data";
            var newsListNewsText = "Notícia";
        }

        $("div.NewsList").each(function () {
            var newsListCode = "";
            newsListCode += "<h2 class='NewsListHeader'>" + $(this).find("h2").text() + "</h2>";
            //THE BASIC CODE FOR THE EVENT TABLE
            newsListCode += "<table class='NewsList'>";
            newsListCode += "<tr class='Header'>";
            newsListCode += "<td class='NewsDate'>" + newsListDateText + "</td>";
            newsListCode += "<td class='NewsName'>" + newsListNewsText + "</td>";
            newsListCode += "</tr>";
            newsListCode += "</table>";
            $(this).after(newsListCode);

            // SHOW EVENT TABLE BY DEFAULT IF INDICATED
            if ($(this).hasClass("NewsListOpen") == true) {
                $(this).next().addClass("NewsListHeaderOpen");
                $(this).next().next().addClass("NewsListOpen");
            }
        });

        // FIND ALL EVENTS AND INSERT THEM INTO THE TABLE
        $("div.NewsList div.News").each(function () {
            var newsName = $(this).find("a.NewsName");
            var newsDate = $(this).find("span.NewsDate");

            var newsCode = "";
            newsCode += "<tr>";

            //DATE CELL
            newsCode += "<td class='NewsDate'>" + $(newsDate).html() + "</td>";

            // NAME CELL
            newsCode += "<td class='NewsName'>";
            if ($(newsName).attr("href") != "") {
                newsCode += "<a href='" + $(newsName).attr("href") + "'>" + $(newsName).html() + "</a>";
            } else {
                newsCode += $(newsName).html();
            }
            newsCode += "</td>";
            newsCode += "</tr>";

            $(this).parent().next().next().append(newsCode);
        });
        $("table.NewsList").each(function () {
            $(this).find("tr:even").addClass("AlternateRow");
            $(this).find("tr:last").addClass("LastRow");
        });
    }

    // THE ANIMATION FOR THE EVENT LIST HEADER
    $("h2.NewsListHeader").bind("click", function () {
        $(this).toggleClass("NewsListHeaderOpen");
        $(this).next().slideToggle("fast");
    });
}


$(document).ready(function() {

    checkLanguage();
    initiateLeftMenu();
    initiateSubLinkContainer();
    initiateBylawPage();
    initiatePublicationPage();
    initiateEventPage();
    initiateUpComingCoursePage();
    initiateTrainingItems();
    initiateCoordinators();
    addLinkInfo();
    writeEventList();
    writeNewsList();
    writeCourseList();
    insertLinkListSpaces();
    writeDcaEmail();
    addRoundedShapes();

});


$(window).load(function() {
    displayPhotoViewer();
});         
