//Common constants.
var  IMAGES_ILLUSTRATION    =   "images\\staticpages\\illustrations\\";
var  FILE_EXTENTION         =   ".jpg";

// Constants for index.html scripts.
var  CONTENT_CONTAINER_ID   =   "imageContent";
var  ACTIVE_HOME_BUTTON     =   "active2"; 
var  INITIAL_PIC_INDEX      =   1;
var  TEXT_EXAMPLE_ID        =   "textExample";
var  PREV_BUTTON_ID         =   "prevButton";
var  NEXT_BUTTON_ID         =   "nextButton";
var  ELEMENT_HIDDEN         =   "hidden";
var  ELEMENT_VISIBLE        =   "visible";
var  ROTATE_INTERVAL        =   5000; // in milliseconds.

// Constants for customers.html scripts.
var  LOGO_IMAGE_ID          =   "logoImage";
var  LOGO_ANCHOR_ID         =   "logoAnchor";
var  CUSTOMER_TEXT_ID       =   "customerText";
var  CUSTOMER_IMAGE_ROOT    =   "customers_";
var  CUSTOMER_LOGO_ROOT     =   "logo_";
var  ACTIVE_CUSTOMER_BUTTON =   "active4";
var  CUSTOMER_IMAGE_ID      =   "customerImage";

//--------------- INDEX.HTML -----------------------

// Image groups on index.html
var imagesGroups = 
{
    games : 
    {
        imageFileName : "homepage_games",
        imagesCount : 6,
        imagesDescriptions :
        [
           "Example: Backup CD",
           "Example: Gift CD in DVD Case",
           "Example: Backup CD",
           "Example: Mailer",
           "Example: CD Menu",
           "Example: CD Mac Menu" 
        ]       
    },
    emails :
    {
        imageFileName : "homepage_email",
        imagesCount : 1,
        imagesDescriptions :
        [
           "Example: Email Backup CD in DVD Case"          
        ]  
    },
    photo :
    {
        imageFileName : "homepage_photos",
        imagesCount : 5,
        imagesDescriptions :
        [
           "Example: Archive CD for Photos",
           "Example: Archive CD Packaging (DVD Case and Mailer)",
           "Example: Archive CD Viewer",
           "Example: Video DVD",
           "Example: Navigation Menu for Video DVD"           
        ] 
    },
    movies :
    {
        imageFileName : "homepage_movie",
        imagesCount : 3,
        imagesDescriptions :
        [
           "Example: Video DVD",
           "Example: Video DVD",
           "Example: Video DVD"
        ]
    }
};

var picIndex = INITIAL_PIC_INDEX;
var currentGroupID = "games";
var interval;

// Handler of onclick event for each of the image group buttons.
function groupButtonClick(obj)
{
    SetIntervalForNext();
    var currentClass = obj.className;     
        
    if (!IsAlreadyActive(currentClass))
    {
       changeImageGroup(obj.id);
    }
}

// Handler of onclick event for button NEXT.
function nextInGroup(obj)
{
    interval = window.clearInterval(interval);
    getNextInGroup();
}

function getNextInGroup()
{
    picIndex++;
    if (picIndex > imagesGroups[currentGroupID].imagesCount)
    {
        picIndex = INITIAL_PIC_INDEX;
    }
    UpdateImageSrc();
}

// Handler of onclick event for button PREV.
function previousInGroup(obj)
{
    window.clearInterval(interval);
    getPrevInGroup();
}

function getPrevInGroup()
{
    picIndex--;
    if (picIndex < INITIAL_PIC_INDEX)
    {
        picIndex = imagesGroups[currentGroupID].imagesCount;
    }
    UpdateImageSrc();
    return false;
}

function IsAlreadyActive(cssClass)
{
    var classes = cssClass.split(' ');
    
    var i = 0;
    while (i < classes.length && classes[i] != ACTIVE_HOME_BUTTON) i++;
    if (i == 0 || i == classes.length)
    {
        return false;
    }
    return true;   
}

function changeImageGroup(elementID)
{
    picIndex = INITIAL_PIC_INDEX;
    changeActiveClass(currentGroupID, elementID);
    currentGroupID = elementID;
    UpdateImageSrc();  
    ChangePrevNextButtonsVisibility();  
}

function getImageSrc()
{
    return IMAGES_ILLUSTRATION + imagesGroups[currentGroupID].imageFileName + picIndex + FILE_EXTENTION;
}

function changeActiveClass(oldActiveID, newActiveID)
{
    var oldActiveElem = document.getElementById(oldActiveID);     
    var newActiveElem = document.getElementById(newActiveID);
    oldActiveElem.className = "";   
    newActiveElem.className = ACTIVE_HOME_BUTTON;
}

function SetIntervalForNext()
{
    interval = window.clearInterval(interval);
    interval = window.setInterval("getNextInGroup()", ROTATE_INTERVAL);
}

function LoadIndex()
{
    UpdateImageSrc();
    SetIntervalForNext();
}

function UpdateImageSrc()
{
    var imageContainer = document.getElementById(CONTENT_CONTAINER_ID); 
    imageContainer.src = getImageSrc();
    
    var imageDescriptor = document.getElementById(TEXT_EXAMPLE_ID);
    imageDescriptor.innerHTML = getImageDescription();
    
    //SetButtonsVisibility(); 
}

function ChangePrevNextButtonsVisibility()
{
    if (imagesGroups[currentGroupID].imagesCount <= 1)
    {
        showPrevButton(ELEMENT_HIDDEN);
        showNextButton(ELEMENT_HIDDEN);
    }
    else
    {
        showPrevButton(ELEMENT_VISIBLE);
        showNextButton(ELEMENT_VISIBLE);
    }
}

function getImageDescription()
{
    return imagesGroups[currentGroupID].imagesDescriptions[picIndex - INITIAL_PIC_INDEX];
}

function SetButtonsVisibility()
{
    // Show/Hide Prev button.
    if (picIndex == INITIAL_PIC_INDEX)
    {
        showPrevButton(ELEMENT_HIDDEN);
    }
    else
    {
        showPrevButton(ELEMENT_VISIBLE);
    }
   
    
    // Show/Hide Next button.
    if (picIndex == imagesGroups[currentGroupID].imagesCount)
    {
        showNextButton(ELEMENT_HIDDEN);  
    }
    else
    {
        showNextButton(ELEMENT_VISIBLE);
    }
}

function setButtonVisibility(button, isDisplayed)
{
    button.style.visibility = isDisplayed;
}

function showPrevButton(isDisplayed)
{
    var prevBut = document.getElementById(PREV_BUTTON_ID);
    setButtonVisibility(prevBut, isDisplayed);
}

function showNextButton(isDisplayed)
{
    var nextBut = document.getElementById(NEXT_BUTTON_ID);
    setButtonVisibility(nextBut, isDisplayed);
}

//--------------- CUSTOMERS.HTML -----------------------

var customerInfo = 
{
    gamehouse : 
    {  
        text : "GameHouse, the industry leader in creating dynamic, high quality games and applications. GameHouse has distinguished itself in the online game industry through unique code development, superior graphics and compelling game play. GameHouse currently has over 60 different online games including action, puzzle, casino, sports, card and board games. \"We created GameHouse with the goal of establishing a successful business that would bring entertainment to millions of people,\" said Garr Godfrey, CEO of GameHouse.",
		logoRef : "http://www.gamehouse.com/"
	},
	wildtangent : 
	{
	     text : "WildTangent is the leading online game publisher. The company's Web Driver platform, comprised of authoring, compression and delivery technologies, with over 100 million users and growing, is the most ubiquitous online gaming platform on the market today. WildTangent operates WildGames.com, a leading online games property, where it publishes hundreds of the top selling online titles from its own WildStudios, as well as the other leading casual game developers.",
	     logoRef : "http://www.wildtangent.com/"
	},
	zylom : 
	{
	     text : "Zylom is a leading European developer and publisher of casual games. Their in-house games studio creates word- and puzzle games dedicated to the European market. Furthermore, they publish localized titles of the best of breed casual games from top game developers such as PopCap and GameHouse. From Zylom, you get the best possible casual games available!",
	     logoRef : "http://www.zylom.com/"
	},
	popcap : 
	{
	    text : "PopCap's goal is to create simple but deep games that literally everyone can enjoy! You can play all their web games instantly right in your browser... or quickly download the Deluxe versions in just a few minutes, even with a slow modem connection. They have nearly twenty employees and a host of contractors and development partners. PopCap games can be found on numerous different platforms, from the web to PCs to Macs, to PDAs and cell phones, even mid-flight airline entertainment.",
	    logoRef : "http://www.popcap.com/"
	},
	trymedia : 
	{
	    text : "Trymedia Systems secure digital delivery services provide the neutral foundation for a wide range of solutions dedicated to optimizing game sales for top-tier PC content developers and publishers. Trymedia also operates the worlds largest B2B marketplace for downloadable games, through which major portals and other high-traffic destinations, as well as the largest P2P Networks, make a catalogue of ActiveMARK-enabled content available to consumers worldwide.",
	    logoRef : "http://www.trymedia.com/"
	},
	shockwave : 
	{
	    text : "A marketer and distributor of digital entertainment, AtomShockwave Corp. was formed by the 2001 merger of Internet pioneers Shockwave.com and AtomFilms. These powerful brands remain the company's consumer flagships today. Shockwave.com is the world's leading destination for interactive entertainment, offering a broad selection of games that attract players of all ages. AtomFilms is where the Web goes to watch movies, providing on-demand viewing of over 1,500 world-class animations and short films. Collectively, more than 20 million loyal entertainment fans visit the AtomShockwave sites each month.",
	    logoRef : "http://www.shockwave.com/"
	},
	spintop : 
	{
	    text : "SpinTop Games&trade; - The Place to Play! SpinTop offers over 150 of the best download games which are available from it's web site <a href=\"http://www.SpinTop-Games.com\" target=\"blank\">www.SpinTop-Games.com</a>. Download and play puzzle, word, mahjong, and action games in a safe & secure family friendly environment. The company's studio division has created market leading titles such as Mahjong Escape&trade; - Ancient China (<a href=\"http://www.MahjongEscape.com\" target=\"blank\">www.MahjongEscape.com</a>) and Mystery Solitaire&trade; - Secret Island (<a href=\"http://www.MysterySolitaire.com\" target=\"blank\">www.MysterySolitaire.com</a>).",
	    logoRef : "http://www.spintop-games.com/"
	},
	realarcade : 
	{
	    text : "RealNetworks, Inc. provides the universal platform for the delivery of any digital media from any point of origin across virtually any network to any person on any Internet-enabled device anywhere in the world. RealNetworks, Inc. develops end-to-end solutions that allow everyone - from Fortune 500 companies with locations worldwide to individuals at their desktops or other Internet-enabled devices - to create, send and receive audio, video and other multimedia services over the Internet.",
	    logoRef : "http://www.realarcade.com/"
	},
	iwin : 
	{
	    text : "Founded in 2001, iWin is a leading developer and publisher of online casual games for the mass market. The company offers free games, premium download games and skill-based games through its web sites <a href=\"http://www.iwin.com\" target=\"blank\">www.iwin.com</a> and <a href=\"http://www.playsite.com\" target=\"blank\">www.playsite.com</a>. iWin also distributes its games through several leading web properties including Yahoo, Real Networks, MSN, Shockwave and AOL. In 2004, iWins top game, Jewel Quest&trade;, was declared a Finalist for the 2004 Billboard Digital Entertainment Awards as &quot;Downloadable Game of the Year&quot;.",
	    logoRef : "http://www.iwin.com/"
	},
	casuality : 
	{
	    text : "CustomCD was selected by <a href=\"http://casuality.org\" target=\"blank\">Casuality.org</a> to produce the Minna Games CD. This CD contains 19 indie and professional games from publishers around the world looking for distribution, licensing and exposure. The Minna Games CD will be distributed free of charge at the Casuality event in Amsterdam from 7-9 February as well as at the GDC, E3, Casuality Seattle from June 27-29 and other events throughout the year.",
	    logoRef : "http://casuality.org/"
	},
	retro64 : 
	{
	    text : "Retro64, Inc. was created by a professional game developer, Michael W. Boeh, to revive the creative spirit of the C64. They strive to make small, fast, polished games that take no time to learn, yet are fun to play over and over again. They use the latest hardware 3D accelerated graphics and digital stereo music to create game environments that are pleasing to the eye and ear. Sure, Retro64 games are based on concepts that are 10 years old, but they look great and are a complete blast to play.",
	    logoRef : "http://www.retro64.com/"
	},
	acdsee : 
	{
	     text : "ACD Systems is recognized the world over as the leader in image management and technical illustration software, providing the ACD Family of products, headed by ACDSee and Canvas.<br />ACD delivers the leading platforms for image management and technical illustration, giving consumers and professionals everything they need to manage, create, edit, share, and publish content for print, presentation and the Web faster, easier, and more efficiently.",
	     logoRef : "http://www.acdsee.com/"
	},
	broderbund : 
	{
	    text : "Riverdeep Inc. is one of the leading consumer software companies with well-known and award-winning brands that include Broderbund, Edmark, and The Learning Company. Leading Riverdeep titles include The Print Shop, PrintMaster, Mavis Beacon, and Reader Rabbit. Riverdeep has partnered with MakeUsAnOffer.us to help it reach and engage more customers through innovative software promotion and transaction solutions. Included in its programs, MakeUsAnOffer.us will create monthly special promotions that let customers name the price they are willing to pay for software. In addition to creating offers that are fun and engaging for customers, MakeUsAnOffer.us will also make it easier for Riverdeep customers to buy online by offering alternative payment choices like PayPal and eChecks.",
	    logoRef : "http://www.broderbund.com/"
	},
	avanquest : 
	{
	    text : "Avanquest USA, formerly Elibrium, publishes best selling small business software, PC utilities and digital media products including My Mail List, My Deluxe Invoices & Estimates, GhostSurf Pro and PowerDVD Deluxe, to create a powerful software line up of more than 50 products. Avanquest USA products are sold in over 10,000 retail outlets across North America, including Wal-Mart, Staples, Office Depot, Office Max and Comp USA. Avanquest USA has been developing and selling the MySoftware line of small business titles for 17 years. They have consistently sold and marketed their own products and have extended that expertise to more than 10 partner developers.",
	    logoRef : "http://www.avanquest.com/"
	},
	powerplyos : 
	{
	    text : "In 1972 a russian athlete Valery Borozov won the 100 and 200 m dash using a rumoured secret training technique invented by Russian-Professor Yuri Verkhoshansky. The western world discovered secret documents of this training method, translated it and used it to build some of the most explosive athlete in the world. The only problem is the training principles where poorly translated at the time, and because of that, the powerful training method of &quot;plyometrics&quot; is still poorly understood by the western world and is only truly known to the worlds top trainers. <br />Now the most powerful and effective vertical jump program is available by combining Power techniques with Plyometrics.",
	    logoRef : "http://www.powerplyos.com/"
	},
	rosecity : 
	{
	    text : "Rose City Software, the software division of InfiniSource.com, has a worldwide distribution network with customers in virtually every developed country of the world. RoseCity's software division has grown with registered users now in 168 countries worldwide, and has become an industry leader in Internet and PC optimization and productivity enhancement software.<br />Today, RoseCity Software offers more than two dozen award-winning shareware products, and our philosophy remains the same. We will only develop and market top notch software that we would enjoy using ourselves. That's our committment to our customers.",
	    logoRef : "http://www.rosecitysoftware.com/"
	},
	oneabcnet :
	{
	    text : "1-abc.net software for the masses is a young company, founded 2005, consisting of ambitious and highly experienced developers, marketing experts, distributors, designers, translators and product managers. The head office is located in Germany, employees and freelancers are working from offices in seven countries all over the world.<br />1-abc.net's business activities include software development, software distribution and IT consulting.",
	    logoRef : "http://www.1-abc.net/"
	},
	avangate :
	{
	    text : "Avangate B.V. provides solutions for electronic software distribution and reseller management, assisting software companies worldwide in successfully selling their products online and at the same time efficiently managing a distribution network. The companys offer includes an eCommerce platform incorporating an easy to use and secure online payment system plus software marketing services and additional marketing and sales tools such as an affiliate network, automated cross selling options, software promotion management, real time reporting, 24/7 shopper support, and the myAvangate reseller management program specifically designed for software sales.",
	    logoRef : "http://www.avangate.com/"
	},
	kagi :
	{
	    text : "Kagi provides an outsourced online store solution. Kagi is one-stop shopping for you and your customers with all the keys you need for success. Kagi is an e-commerce pioneer serving their client suppliers since 1994. Over the history and continuing today, Kagi's clients operate thousands of stores in over 80 countries, selling digital and physical goods and services to millions of buyers worldwide.",
	    logoRef : "http://www.kagi.com/"
	},
	digitalriver :
	{
	    text : "",
	    logoRef : "http://www.digitalriver.com/"
	},
	conception :
	{
	    text : "ConceptionMedia is a full-service digital production company specializing in documentary work. With its own state of the art land and underwater cameras, sound lighting and editing equipment. ConceptionMedia produces the highest quality films for education, television and theatrical release.",
	    logoRef : "http://www.conceptionmedia.net/"
	}
};

var currentCustomer = "gamehouse";

function click_customer(obj)
{
    // Get current active link.
    var elemOldActiveLink = document.getElementById(currentCustomer);
     
    currentCustomer = obj.id;    
    // Load customer image.
    var elemCustomerImage = document.getElementById(CUSTOMER_IMAGE_ID);
    elemCustomerImage.src = GetCustomerImageFileSrc(obj.id);
    
    // Load customer logo.
    var elemCustomerLogoImg = document.getElementById(LOGO_IMAGE_ID);
    elemCustomerLogoImg.src = GetCustomerLogoImgFileSrc(obj.id);
    
    var elemCustomerLogoLink = document.getElementById(LOGO_ANCHOR_ID);
    elemCustomerLogoLink.href = customerInfo[currentCustomer].logoRef;
    
    // Load customer text.
    //var elemCustomerText = document.getElementById(CUSTOMER_TEXT_ID);
    //elemCustomerText.innerHTML = customerInfo[currentCustomer].text;
    
    // Change active link.
    ChangeActiveLink(elemOldActiveLink, document.getElementById(currentCustomer));
}

function GetCustomerImageFileSrc(customerid)
{
    return IMAGES_ILLUSTRATION + CUSTOMER_IMAGE_ROOT + customerid + FILE_EXTENTION;
}

function GetCustomerLogoImgFileSrc(customerid)
{
    return IMAGES_ILLUSTRATION + CUSTOMER_LOGO_ROOT + customerid + FILE_EXTENTION;
}

function ChangeActiveLink(oldElem, newElem)
{
    oldElem.className = "";
    newElem.className = ACTIVE_CUSTOMER_BUTTON;
}

