// set up and use swfobject to emebed flash in the homepage
var flashvars = {
    data: "inc/assets/sampleData.xml"
};
var params = {
    allowScriptAccess: "sameDomain",
    play: "true",
    type: "application/x-shockwave-flash",
    wmode: "opaque",
    quality: "high",
    bgcolor: "#FFFFFF"
};
var attributes = {
    align: "middle",
    id: "Preloader",
    name: "hero"
};

swfobject.embedSWF("Preloader.swf", "hero", "960", "315", "9.0.28", "playerProductInstall.swf", flashvars, params, attributes);

// set up and use swfobject to emebed flash in the homepage
var spotlight_flashvars = {};
var spotlight_params = {
    allowScriptAccess: "sameDomain",
    play: "true",
    type: "application/x-shockwave-flash",
    wmode: "opaque",
    quality: "high",
    bgcolor: "#FFFFFF"
};
var spotlight_attributes = {
    id: "spotlight_flash",
    name: "spotlight_fla"
};

swfobject.embedSWF("/unisys/inc/flash/spotlight.swf", "spotlight_holder", "328", "137", "9.0.28", "playerProductInstall.swf", spotlight_flashvars, spotlight_params, spotlight_attributes);

//We have a custom function for the tabs on the homepage because
//the flash piece slows the site down, the jQuery tabs function is too slow
UnisysV2.enableHomepageTabs = function() {

	//this function is intended to be passed to the jQuery 'each' method
	function tabify(i, elem) {
		var section = $(elem);

		var tabBarItems  = $('> ul.tab-bar > li, > ul.vertical-tabs > li', section);
			$(tabBarItems[0]).addClass('ui-tabs-selected');

		if ( tabBarItems.length < 1 ) return;

		var nextLevel    = section.children("div");
			nextLevel.addClass('ui-tabs-hide');
			$(nextLevel[0]).removeClass('ui-tabs-hide'); // the first section is visible to start

		tabBarItems.each(function(){
			var me       = $(this);
			var sibs     = me.siblings();
			var myLink   = $('a:first', me);

			var myTarget = myLink.attr('href');
				myTarget = myTarget.slice(myTarget.indexOf('#'))

			var myTab    = $(myTarget, section);
			var sibTabs  = myTab.siblings();

			myLink.click(function(){
				sibs.removeClass('ui-tabs-selected');
				me.addClass('ui-tabs-selected');

				nextLevel.addClass('ui-tabs-hide')
				myTab.removeClass('ui-tabs-hide')

				return false;
			}); // end myLink.click
		}); // end tabBarItems.each

		nextLevel.each(tabify);
	};

    $("div#home-page-content > div").each(tabify);
};

UnisysV2.addHomeStyles = function() {
    /* Add a few CSS styles to hide certain page elements while the page loads */

    var homeStyle = '<style class="loading-styles" id="tab-hide-style">';
    homeStyle +=        'div#whats-hot,';
    homeStyle +=        'div#what-we-do,';
    homeStyle +=        'div#events,';
    homeStyle +=        'div#spotlight,';
    homeStyle +=        'div#three-d-blueprinting,';
    homeStyle +=        'div#tabbed-content-engage,';
    homeStyle +=        'div#tabbed-content-innovate,';
    homeStyle +=        'div#tabbed-content-learn';
    homeStyle +=        '{display:none;}';
    homeStyle +=    '</style>';
    $("head").append(homeStyle);
};

UnisysV2.removeHomeStyles = function(id) {
    $('style#home-style').remove();
};

UnisysV2.addHomeStyles();
$(document).ready(function(){
    if ($('body').hasClass('homepage')) {
        UnisysV2.removeHomeStyles();
        UnisysV2.enableHomepageTabs();
    }
});

