//=====================================================================||
//               NOP Design Media Cycling Script                       ||
//                                                                     ||
// For more information on SmartSystems, or how NOPDesign can help you ||
// Please visit us on the WWW at http://www.nopdesign.com              ||
//                                                                     ||
// The media cycler is available as freeware from NOP Design, under the||
// GNU Public License.  You must keep this comment unchanged in your   ||
// code.  For more information contact Scott@NopDesign.com             ||
//                                                                     ||
// MediaCyle Script Module, V.1.0.0                                    ||
//=====================================================================||
//---------------------------------------------------------------------||
// INTERNAL GLOBAL VARIABLES                                           ||
// PURPOSE:     Internal use only, do not modify.                      ||
//---------------------------------------------------------------------||
var xMediaContent  = new Array();
var xMediaImage    = new Image();
var MEDIAIMAGE = new Image();
var iCurrentImage  = -2;
var CycleToUse     = true;
var CycleTrue	   = true;
var CycleFalse     = false;
var iInternalCount = 50000;
var xTimerHandle   = null;
var bTimerRunning  = false;
var bStopShow  = false;
var strSorry  = "I'm Sorry, your cart is full, please proceed to checkout.";
var strOrdered = "This item is already in your cart.  Please make another selection or proceed to Checkout.";
//---------------------------------------------------------------------||
// USER DEFINED VARIABLES                                              ||
// PURPOSE:     Set these variables to customize your script           ||
//              TimeInSecondsBetweenCycles - Seconds to wait before    ||
//                                           cycling to the next image ||
//              LoadInNewWindow            - When true, the link will  ||
//                                           be opened in a new window ||
//                                           otherwise, it will load in||
//                                           the current window.       ||
//              WrapAtEnd                  - Wraps to start at end.    ||
//                                                                     ||
//              MEDIAIMAGE                - Needs defined in your HTML ||
//                                           page as an image name.    ||
//---------------------------------------------------------------------||
var TimeInSecondsBetweenCycles = 600.0;
var BaseCycleTime = 600.0;
var StaticCycleTime = 600.0;
var LoadInNewWindow = false;
var WrapAtEnd       = true;
var URL = "";
var windowName = "";
var iIndex;

//---------------------------------------------------------------------||
// MEDIA FILES TO LOAD                                                 ||
// PURPOSE:     This is the image that you wish displayed, followed by ||
//              the URL to link to.  All images should be on even      ||
//              numbered lines, URLS on odd.  Pay careful attention to ||
//              increment the counter inside of the [] symbols when you||
//              add more images.  There is no maximum to the amount of ||
//              images you can load.                                   ||
//---------------------------------------------------------------------||

xMediaContent[0] = "./images/ls101set.gif";
xMediaContent[1] = "lovesps.html#birthday";



var args = new Object (); // where to put the data
var i,pos,argname,value;

function GetArgs () { 

var query = location.search.substring(1); // get query string
var pairs = query.split (",");     // break at comma
  for (i=0; i<pairs.length; i++) {
    pos = pairs[i].indexOf ("=");  // look for name=value
    if (pos == -1) continue;       // skip if not found
    argname = pairs[i].substring (0, pos); // get name
    value = pairs[i].substring (pos + 1);  // get value
    args[argname] = value;         // store as property
  }
alert(strSorry);

return (args); // return object
}


//---------------------------------------------------------------------||
// FUNCTION:    MediaStopShow                                              ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     Moves the media                                        ||
//---------------------------------------------------------------------||
function MediaStopShow()
{
    bStopShow = true;
    //TimeInSecondsBetweenCycles = BaseCycleTime;
    MediaStop();
    
}



//---------------------------------------------------------------------||
// FUNCTION:    MediaStop                                              ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     Moves the media                                        ||
//---------------------------------------------------------------------||
function MediaStop()
{
    if( bTimerRunning )
        clearTimeout( xTimerHandle );
    bTimerRunning = false;

    if( bStopShow ){
        bStopShow = false;
        bTimerRunning = true;
        xTimerHandle   = setTimeout("window.close()", 5000);
		   }
}




//---------------------------------------------------------------------||
// FUNCTION:    MediaInternalCycle                                     ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     Internal media cycle routine                           ||
//---------------------------------------------------------------------||
function MediaInternalCycle()
{
    (iCurrentImage == (xMediaContent.length - 2)) ? iCurrentImage = 0 : iCurrentImage+=2;
    if( document.MEDIAIMAGE ) document.MEDIAIMAGE.src = xMediaContent[iCurrentImage];

    xTimerHandle   = setTimeout("MediaInternalCycle()", iInternalCount);
    bTimerRunning  = true;
window.focus();
}


//---------------------------------------------------------------------||
// FUNCTION:    MediaStart                                             ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     Starts the media cycling. Call with 'OnLoad' from body ||
//              tag to have an image start cycling on page load.       ||
//---------------------------------------------------------------------||
function MediaStart()
{

   
  // iCurrentImage = iIndex;
 window.focus();   
    iInternalCount = TimeInSecondsBetweenCycles * 1000;    
    
	MediaStop();
   
    MediaInternalCycle();
    if (CycleToUse)
    	TimeInSecondsBetweenCycles = BaseCycleTime;
    else	
	TimeInSecondsBetweenCycles = StaticCycleTime;	
   
}

//---------------------------------------------------------------------||
// FUNCTION:    SelectedMediaStart                                     ||
// PARAMETERS:                                     ||
// RETURNS:                                                            ||
// PURPOSE:     Starts the media cycling. Call to Display Specific     ||
//              image for click from catalog page.                     ||
//---------------------------------------------------------------------||
function SelectedMediaStart(imageURL)
{
//alert(imageURL);
var imagetoshow ="";
 imagetoshow ='./images/'+imageURL+'.gif';
 //alert (imagetoshow);
xMediaContent[0] = imagetoshow;
iCurrentImage=(0) ;
       TimeInSecondsBetweenCycles  = StaticCycleTime;
 
      CycleToUse = CycleFalse;
       //MediaStop();
	//MediaInternalCycle();
       MediaStart();
         
}



function createStaticWindow2(wURL) {
    
     
    URL = wURL;
    windowName = "shirtbacks";
 
 var features =
        'width='        + "500" +
        ',height='      + "500" +
        ',directories=' + (0) +
        ',location='    + (0) +
        ',menubar='     + (0) +
        ',scrollbars='  + (0) +
        ',status='      + (0) +
        ',toolbar='     + (0) +
        ',resizable='   + (0) +
	',dependent='   + (1);

    window.open (wURL, windowName, features); 
   
}

//---------------------------------------------------------------------||
// FUNCTION:    create Popup window for enlarged views                 ||
// PARAMETERS:                                                         ||
// RETURNS:                                                            ||
// PURPOSE:     ||
//---------------------------------------------------------------------||


function createStaticWindow3(wURL,wName,winWidth,winHeight) {
    var winhandle;
    URL = wURL;
    windowName = wName;
    var imagetoshow ="";
 imagetoshow ='./images/"'+windowName+'".gif';
 //alert (imagetoshow);
 var features =
        'width='        + winWidth +
        ',height='      + winHeight +
        ',directories=' + (0) +
        ',location='    + (0) +
        ',menubar='     + (0) +
        ',scrollbars='  + (0) +
        ',status='      + (0) +
        ',toolbar='     + (0) +
        ',resizable='   + (1) +
	',dependent='   + (1);

    winhandle = window.open (wURL, windowName, features);
   
  //SelectedMediaStart(imagetoshow); 
}
