var sinsations_optionImages = new Object();
sinsations_optionImages.changeOptionimage = function(attribute_id,option_id)
{
  if(typeof($$('#productimage img')[0]) != 'undefined')
  {
    if(typeof(sinsations_optionImages.originalImage)=='undefined')
      sinsations_optionImages.originalImage = $$('#productimage img')[0].src;
    
    if(typeof($$('.a'+attribute_id+'_o'+option_id)[0])!='undefined')
      $$('#productimage img')[0].src = $$('.a'+attribute_id+'_o'+option_id)[0].rev;
    else
      $$('#productimage img')[0].src = sinsations_optionImages.originalImage;
  }
  
  options = spConfig.getAttributeOptions(attribute_id);
  if(typeof(options)!='undefined')
  {
    for(i=0; i<spConfig.getAttributeOptions(attribute_id).length; i++)
    {
      if(spConfig.getAttributeOptions(attribute_id)[i].id == option_id)
      {
        if(typeof($$('.not-deliverable')[0])!='undefined')
        {
          if(parseInt(spConfig.getAttributeOptions(attribute_id)[i].qty)<=0)
            $$('.not-deliverable')[0].setStyle({display:'inline'});
          else
            $$('.not-deliverable')[0].setStyle({display:'none'});
        }

        break;
      }
    }
  }
}

function addProductToolTips()
{
  var slideshowproducts = new Array();
  
  $$(".product_tooltip").each( function(input,index) {
    new Tooltip(
      input, {
        backgroundColor: "#fff",
        borderColor: "#fff", 
        textColor: "#000",
        textShadowColor: "#FFF",
        opacity: 0.9
      }
    );

    if(typeof(input.rev)!="undefined")
    {
      if(input.rev != null && input.rev!='')
      {
        if((images = unescape(input.rev).split('|')).length>1)
        {
          input.getElementsByTagName('img')[0].id = 'slideshow'+index;
          
          slideshowproducts.push(new Array(input.getElementsByTagName('img')[0].id,images));
/*
          new Fader(input.getElementsByTagName('img')[0].id, images, {
          	fadeInDuration: 0.75,
          	fadeOutDuration: 0.25,
          	displayDuration: 2
          });
*/
        }
      }
    }
  });
  
  if((slideshow = slideshowproducts[Math.floor(Math.random()*slideshowproducts.length)]).length ==2)
  {
    new Fader(slideshow[0], slideshow[1], {
    	fadeInDuration: 0.75,
    	fadeOutDuration: 0.25,
    	displayDuration: 2
    });
  }
  // alert(slideshowproducts);
}
document.observe('dom:loaded', addProductToolTips);


function addHeaderMovie()
{
  container = 'headermovie';
  if(typeof(FLASH_DIR) == 'undefined')
    FLASH_DIR = '/skin/frontend/sinsations/default/flash/';
  
  movies = new Array();
  movies.push({ swf:'colibri.swf',width:104,height:74,x:267,y:11,bg: '#000000' });
  movies.push({ swf:'inkdrop.swf',width:141,height:84,x:270,y:0,bg: '#000000' });
  movies.push({ swf:'vines.swf',width:316,height:81,x:12,y:0,bg: '#000000' });
  
  movie = movies[Math.ceil(Math.random()*movies.length)-1];
  
  $(container).setStyle({
    position: 'absolute',
    zIndex: 1,
    top: movie.y+'px',
    left: movie.x+'px',
    width: movie.width+'px',
    height: movie.height+'px'
  });
  
  swfobject.embedSWF(FLASH_DIR+movie.swf, container+'_video', movie.width, movie.height, "8", false,false, {quality:"high",wmode:"opaque",scale:"scale",salign:"tl",menu:"false",bgcolor:movie.bg}, false);
}
document.observe('dom:loaded', addHeaderMovie);


function noRightClickOnImages() {
  if(document.images)
    for(i=0;i<document.images.length;i++)
      document.images[i].oncontextmenu = function() { return false; };
}
document.observe('dom:loaded', noRightClickOnImages);


document.observe('dom:loaded', function(){
  var now = new Date();
  var t = Date.parse(now.toGMTString());

  if($('drsin')!=null)
  {
    swfobject.embedSWF(FLASH_DIR+'drsin-banner.swf?t='+t, 'drsin', '100%', '100%', "8", false,{}, {quality:"high",wmode:"transparent",scale:"noscale",salign:"tl",menu:"false"}, false);
    if(!swfobject.hasFlashPlayerVersion("8") && typeof(DRSIN)!="undefined")
    {
      Element.insert($('drsin'), '<a href="'+DRSIN[1]+'"><img src="'+DRSIN[0]+'" alt="'+DRSIN[2]+'" style="width:250px;height:600px" /></a>');
    }
  }
  
  if($$('.swfheadline')!=null && $$('.swfheadline').length>0)
  {
    var swfheadlinecounter = 0;
    
    $$('.swfheadline').each(function(el,index){
    
      if(el.childElements()[0]!=null)
      { 
        if(el.childElements()[0].readAttribute('id')==null)
          el.childElements()[0].writeAttribute('id','swfheadline'+(swfheadlinecounter++));

        tempid = el.childElements()[0].readAttribute('id');
        
        classnames = el.className;
        
        if(classnames!=null && classnames.indexOf(' ')>-1)
        { 
          classnames = classnames.split(' ');
          filename = '';
          newclasses = new Array();
          for(i=0; i<classnames.length; i++)
          {
            if(classnames[i]!='swfheadline')
            {
              if(filename=='')
                filename = classnames[i];
              else
                newclasses.push(classnames[i]);
            }
          }

          if(newclasses.length>0)
            newclasses.join(' ')+' swfheadline';
          else
            newclasses = 'swfheadline';
        
          if(filename!='')
          {
            oldclass = el.className;
            el.className = newclasses;

            swfobject.embedSWF(FLASH_DIR+'headline/'+filename+'.swf?t='+t, tempid, '100%', '100%', "8", false,{}, {quality:"high",wmode:"transparent",scale:"noscale",salign:"tl",menu:"false"}, false);
            if(swfobject.getFlashPlayerVersion().major < 9)
            {
              el.innerHtml = '';
              el.className = oldclass;
            }
          }
        }
      }
      // el.removeClass('swfheadline');
    });
    
    
  }
  
  if(navigator.platform.toLowerCase().indexOf('mac')>-1 && navigator.userAgent.toLowerCase().indexOf('firefox'))
  {
/*
    if(document.getElementsByTagName('body')[0].className.indexOf('cms-homepage')>-1)
      document.getElementsByTagName('body')[0].style.paddingBottom='60px';
    else if(document.getElementsByTagName('body')[0].className.indexOf('cms-index-defaultnoroute')>-1)
      document.getElementsByTagName('body')[0].style.paddingBottom='190px';
*/
  }     
});
