﻿

var homePage;


$(document).ready(function()
{		
	homePage = 
	{
		bannerObj: function (banner, className, swfUrl)
        {
            var bannerObjPub = this;
            bannerObjPub.className = className;
	        bannerObjPub.banner = $(banner);
	        bannerObjPub.link = bannerObjPub.banner.find("a");
	        bannerObjPub.swfUrl = swfUrl;

	        bannerObjPub.link.click(function(){
	            homePage.LoadBanner(bannerObjPub)
	           return false;
	        });
        },
        

        bannerList: new Array(),

        timer: null,
        modeIndex: 0,

		//timer: setTimeout("homePage.ScrollBanner()", 5000),
		
		ScrollBanner: function()
		{
		    if(homePage.modeIndex == 4)
		    {
		        homePage.modeIndex = -1;
		    }

		    homePage.LoadBanner(homePage.bannerList[++homePage.modeIndex])
			homePage.timer = setTimeout("homePage.ScrollBanner()", (homePage.modeIndex == 3 ? 8000 : 5000));
		},
			
		LoadBanner: function(localBannerObj)
		{
		    clearTimeout(homePage.timer);
		    
		    $("#innerbox .banner-link").attr("href", localBannerObj.link.attr("href"));
		    
			// check if they have flash installed
			if (homePage.biteBannerFlash.hasFlash)
			{
			    //create timer to stop browser doing too much at once
			    var t = setTimeout(function(){ homePage.biteBannerFlash.loadSwf(localBannerObj.swfUrl); }, 1);
			}
		
			//remove previous classes
			homePage.RemoveBannerClasses();
			
			// load relevant css classes to UL container and A tags
			$("#innerbox").addClass(localBannerObj.className);
			localBannerObj.link.addClass("current");			
		},
		
		RemoveBannerClasses: function()
		{
			for(var i = 0; i < homePage.bannerList.length; i++)
			{
				$("#innerbox").removeClass(homePage.bannerList[i].className);
				homePage.bannerList[i].link.removeClass("current");
			}
		},
	    
	    biteBannerFlash: new BiteBannerFlashObject(
	    {
			embedPosition: {element: "#innerbox .content .banner-link", position: "before"},
			installHtmlLocation: "#bottom-hor-nav ul",
		    flashId: "biteBannerFlash",
		    swfUrl: "Content/flash/bite-banner.swf",
		    objectRef: "homePage.biteBannerFlash",
		    debug: false
		})	
	};
	
	homePage.biteBannerFlash.initEvent = function()
	{
       //homePage.biteBannerFlash.loadSwf("Content/flash/bite-banner_soft-sol.swf");
	}
	
    //homePage.biteBannerFlash.embed();

    homePage.bannerList[0] = new homePage.bannerObj(".strip .software", "softwarebox", "Content/flash/bite-banner_soft-sol.swf");
    homePage.bannerList[1] = new homePage.bannerObj(".strip .design", "designbox", "Content/flash/bite-banner_design.swf");
    homePage.bannerList[2] = new homePage.bannerObj(".strip .marketing", "marketingbox", "Content/flash/bite-banner_dig-marketing.swf");
    homePage.bannerList[3] = new homePage.bannerObj(".strip .publishing", "publishingbox", "Content/flash/bite-banner_publishing.swf");
    homePage.bannerList[4] = new homePage.bannerObj(".strip .consultancy", "consultancybox", "Content/flash/bite-banner_consultancy.swf");
});



$(document).ready(function() {
	$("#twitter").getTwitter({
		userName: "bitestudioltd",
		//userName: "Tate",
		numTweets: 3,
		loaderText: "Loading tweets...",
		slideIn: false,
		showHeading: true,
		headingText: "Latest Tweets",
		showProfileLink: true
	});
});



var BiteBannerFlashObject = function(config)
{

	var pub = new Object();
	var flashVersion = "9.0.0";
	var installHtml = "<li class='flash-info'>&nbsp;|&nbsp;<a href='http://www.adobe.com/go/getflashplayer'>Install the latest Adobe Flash plugin to enhance this page.</a></li>"

	var jqEmbedPosition = $(config.embedPosition.element);
	var jqInstallHtmlLocation = $(config.installHtmlLocation);

    pub.hasFlash = false;
		
	if (config.debug)
	{
		var jqDebugContainer = $("<div class='debug'><h1>debug</h1></div>");
		
		if (config.embedPosition.position = "before")
		{
		    jqEmbedPosition.before(jqDebugContainer);
		}
		else if (config.embedPosition.position = "after")
		{
		    jqEmbedPosition.after(jqDebugContainer);
		}
		
		jqDebugContainer.css("position", "absolute")
		jqDebugContainer.css("top", "0")
		jqDebugContainer.css("right", "0")
	}


	pub.embed = function()
	{
		pub.debug("embedding");
		
		if (swfobject.hasFlashPlayerVersion(flashVersion))
		{
		    pub.hasFlash = true;
		    
		    if (config.embedPosition.position = "before")
		    {
		        jqEmbedPosition.before("<div id='"+config.flashId+"'></div>");
		    }
		    else if (config.embedPosition.position = "after")
		    {
		        jqEmbedPosition.after("<div id='"+config.flashId+"'></div>");
		    }
				
			var flashvars =
			{
				initFunction: config.objectRef + ".init",
				debugFunction: config.objectRef + ".debug"
			};
			
			var params =
			{
			    wmode: "transparent"
			};
			
			var attributes  = {};
			
			// Embed Flash with swfobject
			swfobject.embedSWF(config.swfUrl, config.flashId, 100, 100, flashVersion, "", flashvars, params, attributes);
		}
		else
		{
			jqInstallHtmlLocation.append($(installHtml));
		}
	}


	pub.initEvent = function() {}

	var initReal = function() {
		pub.debug("initialised");
		// Flash is ready to recieve calls
		pub.initEvent();
	}
	// Started from Flash
	pub.init = function() {
		pub.debug("initialising");
		// Avoid FireFox crash by taking the methods away from the Flash function call
		var t = setTimeout(function(){ initReal(); }, 1);
	}
	
	pub.debug = function(message) {
		if (config.debug) {
			jqDebugContainer.append("<p>"+message+"</p>");
		}
	}

	// Call Flash function
	pub.loadSwf = function(swfUrl) {
		document.getElementById("biteBannerFlash").loadSwf(swfUrl);
		return false;
	}

	// Return public methods and variables
	return pub;
}

