/* Create a namespace */
var UnisysV2 = {};

//This function adds links to select all checkboxes on the registration page and my profile page
UnisysV2.addSelectAllLinks = function() {
    $("div.interest-column").each(function() {
		var curCol = $(this);
		$("ul", curCol).before('<a class="select-all-link">Select All</a>');
        $("a.select-all-link", curCol).click(function() {
			$('input[type="checkbox"]', curCol).attr('checked', true);
        });
    });
};

UnisysV2.autoFill = function(id, content) {
    $(id).each(function() {
        var elem   = $(this);
        if (elem.val() == "") {
			var filled = true;
            var h = elem.attr('id') + 'sample';
            elem.parent().css({position:"relative",top:"0",left:"0"});
            elem.after('<div id="' + h + '" style="color:#AAA;position:absolute;left:160px;top:5px;">' + content + '</div>');

            $('#' + h).click(function(){
                if ( filled ) {
                    $('#' + h).remove();
                    elem.focus();
                    filled = false;
                }
            });

            elem.focus(function(){
                if ( filled ) {
                    $('#' + h).remove();
                    filled = false
                }
            });
        }
    });
};

UnisysV2.enableSelectCountry = function(){
	var COOKIE_NAME = 'countryChoice';
	var cookieValue = $.cookie(COOKIE_NAME);
	//alert("cookieValue" + cookieValue);
	
    $("#country option").each(function(i){
        if (cookieValue == $(this).val() && cookieValue != null) {
        	$(this).attr("selected",true); 
        }
    });

    $("#countrygo").click(function() {
        var selected = $("#country option:selected");
        if ($("#rememberme").is(":checked"))
        	{
				$.cookie(COOKIE_NAME, selected.val(), { expires: 999 }); // set cookie with an expiration date 999 days in the future
			}
		window.open( selected.val() );
	});
};

//This function activates the tabs on pages throught the site
//If called without any arguments then it attempts to activate all tabs on a page
//If called with a selector string then it will only activate tabs on those <UL>s
UnisysV2.enableTabs = function(id) {
    //homepage has its own tab code because this runs too slow with the homepage flash
    if ($("body").hasClass("homepage")) return;

    //if an id is supplied then just tabify that element
    if (id) {
        var tabBar = $(id);
        if ( tabBar && tabBar.length > 0 ) {
            UnisysV2.removeEmptyTabs(id);
            $(id).tabs();
        }
        return;
    }

    $("ul.tab-bar, ul.toggle-bar, ul.vertical-tabs, ul.core-competencies, ul.wide-tab-bar").each(function() {
        //don't tabify if the ul has already been tabified
        if (!($(this).hasClass("ui-tabs-nav"))) {
            UnisysV2.removeEmptyTabs(this);
            $(this).tabs();
        }
    });

    //special case:  tabs in the right sidebar on the support page
    if ($("body").hasClass("support")) {
        //build a list of the right sidebar sections
        var sbList = [];
        $('#right-sidebar div.sidebar-section').each(function(){
            sbList.push(this);
            $(this).hide();
        });

        //show the section corresponding to the currently clicked tab
        var t = $('ul.vertical-tabs').tabs();
        var sel = t.data('selected.tabs');
        $(sbList[sel]).show();

        //functionality to show sidebar sections when tabs are changed
        $("ul.vertical-tabs").bind('tabsselect', function(event, ui){
            $(sbList).hide();
            $(sbList[ui.index]).show();
        });
    }
};

//This function is called by the 'enableTabs' function. It removes empty tabs.
UnisysV2.removeEmptyTabs = function(t) {
	if (!t) return;
    t = $(t);
    if (t.length == 0) return;

	var myTabs = $("li", t);
	if (myTabs.length == 0) return;

	myTabs.each(function(){
		var myA = $("a", this)[0];
		if (!myA) {
			$(this).remove();
			return;
		}

		var myHref = myA.href.slice(myA.href.indexOf("#"));

		var myInner = $(myHref);
		if ( myInner.length == 0 ) {
			$(this).remove();
			return;
		}

		var myHTML = myInner.html();
		if ( myHTML.match(/^\s*$/)) {
			$(this).remove();
			myInner.remove();
			return;
		}
    });

    //if these tabs are not the main content tabs then we are done now
	if (t != 'ul.tab-bar') return;

	//if there are no tabs at all then we want to remove the whole tab section,
	//but ONLY if it is the main column tabs
    myTabs = $("li", t);
    if (myTabs.length == 0) {
        $(".offering-tabbed-content, .tabbed-content").remove();
        return;
    }
};

UnisysV2.fixInternalLinks = function() {
	var all_links = $('.inner-tabbed-content a[href]');
	var local_links = all_links.filter(function() {
			return this.href.match(/#.+/);
	});

	local_links.each(function() {
		var target_href = this.href.slice(this.href.indexOf('#'));
		var target = $(target_href);

		var other_links = $('ul.tab-bar a[href$=' + target_href + ']');

		if ( target.length > 0 && other_links.length > 0 ) {
			$(this).click(function() {
				$(other_links[0]).click();
				return false;
			});
		}
	});
};

UnisysV2.enableInsightsReveal = function() {
	$(".insights-group").each(function() {
		var myList   = $(this);
		var myToggle = myList.next(".insights-reveal");

		if ( myList.hasClass('insights-reveal-activated') ) return; //this one is already done
		else myList.addClass('insights-reveal-activated');

		var listLength = myList.children("> li").length
		if ( listLength == 0 || myList.html().match(/^\s*$/) ) { //if the list is empty then just remove and be done
			myToggle.remove();
			myList.remove();
			return;
		}
        if ( listLength == 1 ) { //if there is only one item then we dont need at toggle (right?)
			myToggle.remove();
            return;
        }

		var myDuration  = listLength * 100;
		var closed      = true;
		var firstClick  = true;
		var firstItem   = myList.children("li:first");
		var fakeItem    = $(document.createElement("ul")).
						  attr("class", "insights-group").
						  append( firstItem.clone() );
        var showText    = myToggle.text();
        var hideText    = showText.replace(/^Show/, "Hide");

		myList.before(fakeItem);
		myList.hide();
		firstItem.hide();

		myToggle.click(function() {
			if (closed) {
				myList.slideDown(myDuration, function() {
					if (firstClick) {
						firstItem.show();
						fakeItem.remove();
						firstTime = false;
					}
				});
                myToggle.text(hideText);
			} else {
				myList.slideUp(myDuration);
                myToggle.text(showText);
			}
			closed = !closed;
			myToggle.toggleClass("insights-revealed");
			return false;
		});
	});
};

//The left rail navigation menu (top section)
UnisysV2.enableCollapsibleNavigationMenu = function() {
    //menu level variables
    var selection = null;
    var last      = 0;
    var delay     = 250;
    $("ul.collapsible-navigation-menu li.head").css("backgroundColor", "#EEE"); //This needs to be set for the jquery.color module.
    $('ul.collapsible-navigation-menu li.head').each(function(){
        //item level variables
        var item    = $(this);
        var heading = $('> a', this);
        var list    = $('ul', this);
        var timeout;

        list.hide()
        item.hover(
            function() {
                var openMenu = function() {
                    var now = new Date().getTime();
                    if ( (now - last) > (delay * 3) ) {
                        selection = item;
                        window.clearInterval(timeout);
                        item.animate({backgroundColor:"#CCC"}, delay, function(){
                            if ( selection == item ) {
                                last = now;
                                heading.addClass("open");
                                list.slideDown(delay);
                            }
                        });
                    }
                }
                timeout = window.setInterval(function() {openMenu()}, 5);
            },
            function() {
                selection = null;
                window.clearInterval(timeout);
                item.animate({backgroundColor:"#EEE"}, delay, function(){
                    list.slideUp(delay);
                });
                heading.removeClass("open");
            }
        );
    });
};

//Left column menu, bottom section (top news, case studies, etc)
UnisysV2.enableAccordionMenu = function() {
    $("ul.accordion-menu").accordion({
        header: 'a.head',
        active: false,
        autoHeight: false
    });
};

UnisysV2.enableToggle = function() {
	$(".view-offerings-toggle").each(function() {
		var myToggle = $(this);
		var myList   = myToggle.next("ul");

		if ( myToggle.hasClass('viewtoggleactivated') ) return; //this one is already done
        else myToggle.addClass('viewtoggleactivated');

		if ( myList.length == 0 || myList.html().match(/^\s*$/) ) { //if the list is empty then just remove the whole toggle
			myList.remove();
			myToggle.remove();
			return;
		}

		var L = myList.children("li").length;
		var myDuration = L * 50;
        var isOpen     = false;
        var showText   = myToggle.text();
        var hideText   = showText.replace(/^View/, "Hide");

        myToggle.addClass('collapsed-list');
		myList.addClass('collapsed-list');
		myList.hide();

		myToggle.click(function() {
            if ( isOpen ) {
                myList.slideUp(myDuration);
                isOpen = false;
                myToggle.text(showText);
            } else {
                myList.slideDown(myDuration);
                isOpen = true;
                myToggle.text(hideText);
            }
			myToggle.toggleClass('collapsed-list');
			myList.toggleClass('collapsed-list');
		});
	});
};

//Used for the descriptions on the offerings index pages
UnisysV2.enableShowHideToggle = function() {
    $("ul.show-hide-toggle li.show").click(function(){
        $("p.index-description").show();
    });
    $("ul.show-hide-toggle li.hide").click(function(){
        $("p.index-description").hide();
    });
};

UnisysV2.enableModalPop = function() {
	var modalPop = $('#modal-pop');
    if ( modalPop.length == 0 ) {
        $('#masthead').before('<div id="modal-pop" class="jqmWindow"></div>');
		modalPop = $('#modal-pop');
    }
    modalPop.jqm({
        modal: false,
        ajax:'@href',
        trigger: 'a.open-modal',
        toTop: true,
        vma: this,
        onLoad: function(h) {

			var myHeight    = Math.floor(document.documentElement.clientHeight/2) + 'px';
			var vertMargin  = Math.floor(document.documentElement.clientHeight/4) + 'px';

			h.w.css({'height': myHeight, 'margin-top': vertMargin});

            $('a.open-modal', modalPop).each(function() {
				var myLink = $(this);
                myLink.click(function() {
                    modalPop.jqmHide();
                    var u = myLink.attr("href");
                    u = u.substr(u.indexOf('/unisys/'));
                    $('ul#bottom-navigation li a[href="' + u + '"]').click();
                    return false; //to prevent following the link
                });

            });
        }// end onLoad function
    });
};

UnisysV2.enableSingleFilter = function() {
    $('select.toggle-list').each(function() {
		var toggle = $(this);
        var myList = [];
        toggle.children('option').each(function() {
            myList.push('#' + this.value);
        });

        if ( toggle.children('option[value="showall"]').length == 0 ) {
            for ( var i = 1; i < myList.length; i++ ) {
                $(myList[i]).hide();
			}
		}

        toggle.change(function(){
			var myName = "#" + toggle.val();
			for ( var i = 0; i < myList.length; i++ ) {
				if ( myName == "#showall" || myName == myList[i] ) {
					$(myList[i]).show();
				} else {
					$(myList[i]).hide();
				}
			}
			return false;
        });
    });
};

UnisysV2.enableFilterBar = function(){
    $("form.filter-bar select").change(function(){
        if (this.value == "showall") {
            $("ol.alphabetical-grouping li ol li").show();
            $("h3.industry-type").text("All Industries");
        } else {
            $("ol.alphabetical-grouping li ol li").hide();
            $("ol.alphabetical-grouping li ol li." + this.value).show();
            $("h3.industry-type").show().text($("form.filter-bar select option:selected").text());
        }
    })
};

UnisysV2.enablePopups = function(){
	// Currently limited to only use links in the main content column
	var popDestination;
	var winParams = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width=800,height=600,top=0,left=0";
	
	$("a.popup").each(function () {
		$(this).attr({
			title: "[Opens in pop-up window]"
		});
	})
	.click(function() {
		popDestination = $(this).attr("href");
		newWindow = window.open(popDestination, 'newWin', winParams);
		newWindow.focus();
		return false;
	})
};

UnisysV2.enableMultiFilter = function() {
    $('.inner-tabbed-content, .paginated').each(function() {
        var thisParent  = $(this);
		var myFilters   = $('select.select-filter', thisParent);
        var myPages     = $('#numberSearchResults', thisParent);

		// if there are no filters then we can skip this tab
		// also we don't want to activate a tab more than once
		if ( (myFilters.length == 0 && myPages.length == 0 ) || thisParent.hasClass('selectfilteractivated') ) {
            return;
        } else {
            thisParent.addClass('selectfilteractivated');
        }

		var allItems    = $('.offering-preview', thisParent);
		var currentPage = 0;
		var numPages    = 1;
		var itemList;
		var itemsPerPage;

		// This block just adds first, previous, next, and last links to the pagination
		$('.index-listings', thisParent).append('<div class="index-pagination"></div>');
		var pageDiv = $('div.index-pagination', thisParent);
			pageDiv.append('<a id="first-page" href="">&laquo; First</a>');
			$('#first-page').click(function() {
				gotoPage(0);
				return false;
			});
			pageDiv.append('<a id="previous-page" href="">&lsaquo; Previous</a>');
			$('#previous-page').click(function() {
				gotoPage( currentPage - 1 );
				return false;
			});
			pageDiv.append('<a id="last-page" href="">Last &raquo;</a>');
			$('#last-page').click(function() {
				gotoPage( numPages - 1 );
				return false;
			});
			pageDiv.append('<a id="next-page" href="">Next &rsaquo;</a>');
			$('#next-page').click(function() {
				gotoPage( currentPage + 1 );
				return false;
			});
			pageDiv.append('<ul></ul>');
		var pageUl  = $('ul', pageDiv);
		
		//paginate the list
		var paginate = function(il, ipp) {
			itemList = il;
			itemsPerPage = ipp;
			if ( itemList.length > itemsPerPage ) {

				//clear and repopulate the page links
				pageUl.empty();
				numPages = Math.ceil( itemList.length / itemsPerPage );
				currentPage = 0;

				pageUl.append('<li class="ellipsis">. . .</li>');
				for ( var i = 0; i < numPages; i++ ) {
					pageUl.append('<li><a class="faux-page-link" href="#' + (i + 1) + '">' + (i + 1) + '</a></li>');
				}
				pageUl.append('<li class="ellipsis">. . .</li>');

				$("li.ellipsis", pageUl).hide();
				$('.faux-page-link', pageUl).click(function() {
					gotoPage( parseInt(this.href.substr(this.href.indexOf('#') + 1)) - 1 );
					return false;
				});
				pageDiv.removeClass('paginate-hide');
			} else {
				pageDiv.addClass('paginate-hide');
			}
			gotoPage(0);
		};

		var gotoPage = function(dest) {
			if ( dest < 0 || dest >= numPages ) return;
			currentPage = dest;
			displayItems(itemList, currentPage, itemsPerPage);
			var myLis = $('li:not(.ellipsis)', pageUl);
			myLis.filter('.current-page').removeClass('current-page');

			$('a[href$="#' + (currentPage + 1) + '"]', pageUl).parent("li").addClass("current-page");

			//if there are more then 7 pages then we need to use ellipses
			if ( numPages > 7 ) {
				var lowest  = ( currentPage > 3 ) ? currentPage - 3 : 0;
				var highest = ( currentPage + 4 < numPages ) ? currentPage + 3 : numPages - 1 ;

				if ( lowest > 0 ) $('li.ellipsis:first', pageUl).show();
				else $('li.ellipsis:first', pageUl).hide();
				if ( highest < numPages - 1 ) $('li.ellipsis:last', pageUl).show();
				else $('li.ellipsis:last', pageUl).hide();

				for ( var i = 0; i < numPages; i++ ) {
					if ( i < lowest || i > highest ) {
						$(myLis[i]).hide();
					} else {
						$(myLis[i]).show();
					}
				}
			}
            window.scrollTo(0,0);
		};

		//refresh the list of items
		var updateDisplay = function() {
			var filteredItems = allItems;
			for ( var i = 0; i < myFilters.length; i++ ) {
				if ( myFilters[i] && myFilters[i].criteria ) {
					filteredItems = filteredItems.filter("." + myFilters[i].criteria );
				}
			}
			paginate( filteredItems, myPages.val() );
		};

		//show the list
		var displayItems = function(showItems, curPage, pageLength) {
			allItems.hide();
			if ( showItems.length > pageLength ) {
				var n = (curPage + 1) * pageLength;
				if ( showItems.length < n ) n = showItems.length;
				for ( var i = curPage * pageLength; i < n; i++ ) {
					$(showItems.get(i)).show();
				}
			} else {
				showItems.show();
			}
		};

        var updateOpts = function(f, crit) {
			f.criteria = $(f).
						 empty().                             // clear out the options
						 append( f.opts.filter("." + crit) ). // add the ones that match out criteria
						 find('option:first').                // make sure that the first option
						 attr('selected', 'selected').        // is selected
						 val();                               // and return its value as the criteria
        };

		//setup the filters
		myFilters.each(function(i) {
			var f        = this;
			f.next       = ( i < myFilters.length - 1 ) ? myFilters[i + 1] : null;
			f.active     = ( i == 0 );
			f.criteria   = f.value;
			f.opts       = $('option', f);
			$(f).change(function() {
				f.criteria = f.value;
				if (f.next) updateOpts( f.next, f.criteria );
				updateDisplay();
				return false;
			});
		});

		//setup the pagination menu
		myPages.change(function() {
			updateDisplay();
			return false;
		});

		//after everything is set up we need to
		//trigger a change event to
		//run the pagination function for the first time
		if ( myFilters.length > 0 ) {
			myFilters.change();
		} else {
			myPages.change();
		}
    });
};


UnisysV2.enableRegistrationFormValidation = function(){
    $("input#event-register").submit(function(){
    });
};

UnisysV2.enableDocBarToolTips = function() {
    $("ul#document-actions li").each(function(){
		var me = $(this);
		var myA = $("a", me);
		var myTip = myA.attr('title');
		//create the markup
        me.append('<div class="doc-bar-tool-tip"><p>' + myTip + '<img src="/unisys/inc/img/ui/tooltip-pointer-down.gif"/></p></div>');
		//remove title attribute so that the browser does not generate its own tool tips
        myA.removeAttr("title");
		var myToolTip = $("div.doc-bar-tool-tip", me);
		myA.hover(
			function() {
				myToolTip.show();
			},
			function() {
				myToolTip.hide();
			}
		);
		myA.mousemove(function(e) {
			var myOffset = ( $('body').width() - $('#center').width() ) / 2;
			var width    = myToolTip.children('p').width() + myToolTip.width() - 20;
			var leftPos  = e.pageX - myOffset - width;
			var topPos   = e.pageY - 55;
			myToolTip.css({left: leftPos, top: topPos});
		});
    });
};

// Used on the benefits of joining my unisys page
UnisysV2.setupImageScroller = function() {

    var scroller = $('div#screenshot-scroll');
	if ( scroller.length < 1 ) return;

	var items = $('li', scroller);
		items.hide();
		$(items[0]).show();

	var counter = 0;
	var last    = items.length - 1;

	$('a#prevImg', scroller).click(function() {
		$(items[counter]).hide();

		counter = ( counter > 0 ) ? counter - 1 : last;

		$(items[counter]).show();
	});

	$('a#nextImg', scroller).click(function() {
		$(items[counter]).hide();

		counter = ( counter + 1 < last ) ? counter + 1 : 0;

		$(items[counter]).show();
	});

}; 

UnisysV2.checkUrlForModal = function() {
    var u = (document.location).toString();
    var ind = u.indexOf('#modalpop=');
    if (ind != -1) {
        $('ul#bottom-navigation li a[href="' + u.substr(ind + 11) + '"]').click();
    }
}

/* Used on the My Unisys Edit Profile page */
UnisysV2.nextPrevTabButtons = function() {
	// Attach tab clicks to "Next/Prev tab" buttons
	$('.tab-one').click(function() {
		$('li#profile-tab a').click();
	});
	$('.tab-two').click(function() {
		$('li#interests-tab a').click();
	});
};

UnisysV2.removeJSWarning = function() {
	//hide second tab content and Javascript warning, if Javascript enabled
	$('#my-interests-tabbed-content').hide();
	$('#javascriptrequired').hide();
};

/* Used on the My Unisys Edit Profile page */
UnisysV2.interestsOtherSetup = function() {
	$('#other-text').attr("disabled", true);
	$('#ckbx-other').click(function() {
		(this.checked) ? $('#other-text').removeAttr("disabled").focus() : $('#other-text').attr("disabled", true);
	});
};

// set up the form on 'unisys around the world' part of about unisys section
UnisysV2.setupAroundTheWorld = function() {
    if ( !$('body').hasClass('unisys-around-the-world') ) return;

    var myForm     = $('#locationsForm');

    // to ensure that we only do this once
    if ( myForm.hasClass('aroundtheworldactivated') ) return;
    else myForm.addClass('aroundtheworldactivated');

    var countrySel = $('select#glcountry', myForm);
    var stateSel   = $('select#glstate', myForm);
    var stateLabel = $('label.country-select-label');
    var stateOpts  = $('option', stateSel);

    // dont show states when there are no options
    if ( stateOpts.length <= 1 ) {
        stateSel.hide();
        stateLabel.hide();
    }

    countrySel.change(function() {
        stateSel.val('');
        myForm.submit();
    });
    stateSel.change(function() {
        myForm.submit();
    });
};

UnisysV2.fixSiblingSelectorIE6 = function() {
	$('.offering-preview img ~ h4, .offering-preview img ~ p, .offering-preview img ~ ul, .personnel img ~ h4, .personnel img ~ p, .personnel img ~ ul').css("marginLeft", "148px");
};

UnisysV2.fixSearchEnter = function() {
	var submit_button = $('#masthead #search input[type=submit]');
	$('#masthead #search input[type=text]').keypress(function(e) {
		if( e.which == 13 ) { // 13 is the keycode for the enter key
			submit_button.click();
			return false;
		}
	});
}

UnisysV2.addHideStyles = function() {
    /* Add a few CSS styles to hide certain page elements while the page loads */

    var tabHideStyle = '<style class="loading-styles" id="tab-hide-style">';
    tabHideStyle +=        'div.tabbed-content div.inner-tabbed-content,';
    tabHideStyle +=        'div.offering-tabbed-content div.inner-tabbed-content,';
    tabHideStyle +=        'div.research-tabbed-content div.inner-tabbed-content,';
    tabHideStyle +=        'div.faux-tabbed-content div.inner-tabbed-content div,';
    tabHideStyle +=        'ul.tab-bar li';
    tabHideStyle +=        '{display:none;}';
    tabHideStyle +=        'div.faux-tabbed-content div.inner-tabbed-content div#sortall,';
    tabHideStyle +=        'div.faux-tabbed-content div.inner-tabbed-content div#sortall div,';
    tabHideStyle +=        'div.faux-tabbed-content div.inner-tabbed-content div.featured-topic,';
    tabHideStyle +=        'div.faux-tabbed-content div.inner-tabbed-content div.featured-topic div,';
    tabHideStyle +=        '#tab1';
    tabHideStyle +=        '{display:block;}';
    tabHideStyle +=    '</style>';

    var leftNavTopStyle = '<style class="loading-styles" id="left-nav-top-loading-style">';
    leftNavTopStyle +=        'ul.collapsible-navigation-menu li.head ul,';
    leftNavTopStyle +=        'ul.collapsible-navigation-menu li.current-head ul';
    leftNavTopStyle +=        '{display:none;}';
    leftNavTopStyle +=    '</style>';

    var leftNavBotStyle = '<style class="loading-styles" id="left-nav-bot-loading-style">';
    leftNavBotStyle +=        'ul.accordion-menu li ul,';
    leftNavBotStyle +=        'ul.accordion-menu li div#top-news a.view-all';
    leftNavBotStyle +=        '{display:none;}';
    leftNavBotStyle +=    '</style>';

    var hideOnLoadStyle = '<style class="loading-styles" id="hide-on-load-style">';
    hideOnLoadStyle +=        'div.hide-on-load';
    hideOnLoadStyle +=        '{display:none;}';
    hideOnLoadStyle +=    '</style>';

    var toggleListStyle = '<style class="loading-styles" id="toggle-list-style">';
    toggleListStyle +=        'ul.view-offerings-toggle-list';
    toggleListStyle +=        '{display:none;}';
    toggleListStyle +=    '</style>';

    $("head").append(tabHideStyle);
    $("head").append(leftNavTopStyle);
    $("head").append(leftNavBotStyle);
    $("head").append(hideOnLoadStyle);
    $("head").append(toggleListStyle);
};

UnisysV2.removeHideStyles = function(id) {
    if (id) {
        $(id).remove();
    } else {
        $('style.loading-styles').remove();
    }
};

/* This is called before the page loads */
UnisysV2.addHideStyles();

/* Initialize everything */
$(document).ready(function() {
    /* Get rid of the styles that hide page elements now that we are ready to run the real scripts */
    UnisysV2.removeHideStyles();

    UnisysV2.enableTabs();
    UnisysV2.enableShowHideToggle();
	UnisysV2.enableMultiFilter();
    UnisysV2.enableModalPop();
    UnisysV2.enableSingleFilter();
    UnisysV2.enableFilterBar();
    UnisysV2.enablePopups();
    UnisysV2.enableRegistrationFormValidation();
    UnisysV2.setupImageScroller();
	UnisysV2.enableInsightsReveal();
    UnisysV2.setupAroundTheWorld();
	UnisysV2.fixInternalLinks();

	var t = window.setTimeout(function() {
		UnisysV2.autoFill("#registersection #emailaddress", "johnsmith@email.com");
		UnisysV2.autoFill("#registersection #password", "minimum 6 characters");
	}, 100);//use a time out otherwise these will autofill before some browsers, leading to double stuffed text fields

    UnisysV2.checkUrlForModal();

	//ie6 has a layout bug which can be corrected by forcing a repaint on the left nav
	if ( $.browser.msie && ($.browser.version == 6) ) {
		$('#left-sidebar ul.collapsible-navigation-menu li.head').each(function(){
			var elem = $(this);
			var bgColor = elem.css('backgroundColor');
			if ( bgColor && bgColor != "transparent" ) {
				elem.animate({'backgroundColor': bgColor}, 5);
			}
		});
		// fix another layout issue on the list pages
		UnisysV2.fixSiblingSelectorIE6();
	}
	if ( $.browser.msie && ($.browser.version <= 7) ) {
		UnisysV2.fixSearchEnter();
	}
});
