﻿function rotateImages()
{
  
   var lnkId,evalId,str1,str2,str3,str4,j;
   for(iMyCount = 0; iMyCount < 16; iMyCount++)
    {
   
       j = iMyCount;
       str1 = 'ctl00_WebsiteContent_List_repList_ctl0'
       str2 = '_lnkMoreColours';
       str3 = '_imgProductImage';
       str4 = '_hidColours';
       j = j + '';
    
       str1 = str1.concat(j);
       str1 = str1.concat(str2);
      var arrColours = new Array();
       if(document.getElementById(str1) != null)
       {
         str1 = str1.replace(str2,str3);
         str5 = document.getElementById(str1.replace(str3,str4)).value;
       
         arrColours = str5.split(",");
         
             var length = arrColours.length;
            
         for(iColours = 0; iColours < length; iColours++)
             {
              
              setTimeout("makeCall('" + str1 + "','" + arrColours[iColours] + "')",5000 * (iColours + 1));
    
             }
              
       }
   
  }
}

function makeCall(str1,strColour)
{
   
    opacity(str1, 50, 100, 1000,strColour);
}

function opacity(id, opacStart, opacEnd, millisec,colour) {  
    //speed for each frame  
    var speed = Math.round(millisec / 100);  
    var timer = 0;  
   
    //determine the direction for the blending, if start and end are the same nothing happens  
    if(opacStart > opacEnd) 
    {  
        for(i = opacStart; i >= opacEnd; i--) {  
            setTimeout("changeOpac(" + i + ",'" + id + "','" + colour + "')",(timer * speed));  
            timer++;  
        }  
    } else{  
        for(i = opacStart; i <= opacEnd; i++)  
            {  
            setTimeout("changeOpac(" + i + ",'" + id + "','" + colour + "')",(timer * speed));  
            timer++;  
        }  
    }  
   
} 

function pausecomp(millis)  
{ 
var date = new Date(); 
var curDate = null; 

do { curDate = new Date(); }  
while(curDate-date < millis); 
}  

function changeOpac(opacity,id,colour) {  
  
    elem = document.getElementById(id);

    if(colour != '' && elem.src.indexOf('Colourways') < 1 && elem.src.indexOf('missing') < 1 && elem.src.indexOf('Mens') < 1 ){
        elem.src = elem.src.replace('Main','Colourways');
        strColourway = '_' + colour + '_1';
        elem.src = elem.src.replace('_1',strColourway); 
        
    }
    else if(colour != '' && elem.src.indexOf('Colourways') > 0 && elem.src.indexOf(colour) < 1 && elem.src.indexOf('missing') < 1 && elem.src.indexOf('Mens') < 1){
    
     var aPosition = elem.src.indexOf("_");
     var secondPos = elem.src.indexOf("_", aPosition + 1);
    
     elem.src = elem.src.substring(0,secondPos) + "_1_Medium.jpg"; 
     strColourway = '_' + colour + '_1';
     elem.src = elem.src.replace('_1',strColourway); 
    
    }
    else if(colour == '' && elem.src.indexOf('Colourways') > 0 && elem.src.indexOf('missing') < 1 && elem.src.indexOf('Mens') < 1){
     elem.src = elem.src.replace('Colourways','Main');
  
     var aPosition = elem.src.indexOf("_");
     var secondPos = elem.src.indexOf("_", aPosition + 1);
    
    
     elem.src = elem.src.substring(0,secondPos) + "_1_Medium.jpg"; 
    
    }
    
    var object = elem.style;  
    object.opacity = (opacity / 100);  
    object.MozOpacity = (opacity / 100);  
    object.KhtmlOpacity = (opacity / 100);  
    object.filter = "alpha(opacity=" + opacity + ")";  
} 