// IAG Javascript
commons = {

    /*hover: function(options) {
    $(options.targets).hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });
    }*/

    /* IE6 workaround for left nav */

    hover: function(options) {
        $(options.targets).hover(
            function() {
                if ($(this).hasClass('no-nodes-down'))
                    $(this).removeClass().addClass('no-nodes-down-hover');
                else
                    $(this).addClass('hover');
            },
            function() {
                if ($(this).hasClass('no-nodes-down-hover'))
                    $(this).removeClass().addClass('no-nodes-down');
                else
                    $(this).removeClass('hover');
            });
    }
    ,
    activate: function(options) {
        $(options.targets).click(function() {
            $(this).siblings().removeClass('active');
            if (!$(this).hasClass('active')) {
                $(this).addClass('active');
            }
        });
    }
}

/*insite script*/
slides = {
    ini: function() {
        slides.highlightsSlide();
    },
    highlightsSlide: function() {
        $('#highlights .tabs ul li').click(function() {
            $('#highlights .tabs ul li').siblings().removeClass('active');
            $(this).addClass('active');
            var i = $('#highlights .tabs ul li').index(this);
            var s = $('#highlights .slide:first').width();
            var a = i * s * -1;
            var h = $('#highlights .slide:eq(' + i + ')').height();
            $('#highlights .slide-cont').stop().animate({ 'left': a + 'px' }, '200');
        });
    }
}

$(function() {
var hoverOptions = { targets: '#highlights .tabs ul li, #nav li.down, #nav li.no-nodes-down, #nav li.down li.down, .nav li' };
    commons.hover(hoverOptions);
    var actOptions = { targets : '#nav li.down, #nav li.down li.down' };
	commons.activate(actOptions);
    slides.ini();
});

function leftNavMenu() {
  
    //initial - collapse everything
    $("#nav ul").hide();
    $("#nav li:has(ul)").each(function() {
        $(this).children('.sub').hide();
    });

    //expand the current node(s)
    $("#nav li:has(ul)").each(function() {
        $(this).children('.expand').show();
    });

    //and mark them as active
    $("#nav li.p1.down:has(ul.expand)").each(function() {
        $(this).addClass("active");
    });
    
    //attach click events
    $("li.p1:has(ul.sub)").click(function(event) {
        if (this == event.target) {
				
            var current = this;
            $("#nav li:has(ul)").each(function() {
                if (this != current) $(this).children('.sub').slideUp(400);
            });

            $("ul:first", $(this)).slideToggle(400);
			
			
        }
    });

    $("li.p2:has(ul)").click(function(event) {
        if (this == event.target) {
            var current = this;
            $("li.p2:has(ul)").each(function() {
                if (this != current) 
					$(this).children('.sub').slideUp(400);
					
				//else
					//$(this).removeClass("active");	
					//$(this).children('.sub').hide();
            });
            $("li.p3:has(ul)").each(function() {
                if (this != current) {
					$(this).children('.sub').slideUp(400);
					//$(this).children('.sub').hide();
				}
            });
            $("ul:first", $(this)).slideToggle(400);
        }
    });

    $("li.p3:has(ul)").click(function(event) {
        if (this == event.target) {
            var current = this;
            $("li.p3:has(ul)").each(function() {
                if (this != current) $(this).children('.sub').slideUp(400);
            });
            $("ul:first", $(this)).slideToggle(400);
        }
    });
}

$(document).ready(function() {
    $('#head .navi .navi-main li').hover(
			function() {
			    if ($('div.submenu', this).length > 0) {
			        $('div.submenu', this).css('z-index', '1000');
			        $('.content .tools', this).css('position', 'relative');
			        $('.content .tools', this).css('z-index', '0');
			        $(this).addClass('hover');
			        $(this).not('.active').append('<img src="/_layouts/images/IAG.DI.Branding/menu-arrow.jpg">');
			    }
			},
			function() {
			    if ($('div.submenu', this).length > 0) {
			        $(this).removeClass('hover');
			        $('img', this).remove();
			    }
			}
	);
    leftNavMenu();
});


//printing pages

function toggle(button) {
    switch (button.name.toLowerCase()) {
        case "print":
            PrintPreview()
            break;
        default:
            ;           
    }
    button.blur();
}

function PrintPreview() {
    var sURL = document.location.href;
    if (sURL.indexOf('?') > 0) {
        sURL = document.location + "&PrintPreview";
    }
    else {
        sURL = document.location + "?PrintPreview";
    }
    window.open(sURL);
}

function IfPrintVersion() {
    if (document.location.href.indexOf('PrintPreview') > 0) {

        document.writeln('<style>');
        document.writeln('.col-nav,.col-content-right, .top,#head,#feet,.breadcrumb, .ms-navframe,.ms-bannerframe,.ms-sbtable,.ms-searchform,.ms-sbtopcorner,.ms-sblbcorner,.ms-consoletitleareaframe,.breadCrumb,.ms-consoletitleareaframebottom,.ms-consoleframe,.ms-SPLink,.ms-globallinks,.panel-footer  {display: none;}  ');
        document.writeln('body {background-image:none;}');
        document.writeln('#body .col-content {width:100%;}');
        document.writeln('</style>');
        window.print();

    }
}

//end - print pages

