/* normal function */
function menuSwap(item, current)
{
    var playAnimation = dojo.animateProperty({
        node: item, duration: 210,
        properties: {
            fontSize: {end: '24'},           
            color: {end: '#fff'},
            backgroundColor: {end: '#000'}
        }
    });
    playAnimation.play();
    
    if(current =='') {
        clearTimeout(rotation);
        if(item != curProduct)
            fadePage(item);
    }
    
    dojo.forEach(products, function(prod) {
    	if(prod != current) {
        	if(prod != item) {
        		menuSwapOff(prod)
    		}
    	}
    });
}

function menuSwapOff(item)
{
    var playAnimation = dojo.animateProperty({
        node: item, duration: 210,
        properties: {
            fontSize: {end: '16'},       
            color: {end: '#000'},
            backgroundColor: {end: '#fff'}
        }
    });
	//if(!dojo.exists('index') && item) {
	
    	playAnimation.play();
    //}
}

function selectProduct(name)
{   
    //dojo.byId(name).className = 'selected';
    if(curProduct != name) {
        dojo.byId(curProduct).className = '';
       // if(productClick)
            menuSwap(curProduct,'16','#000','#fff','off')
        //productClick = true;
        clearTimeout(rotation);
        fadePage(name);
    }
}

function productRotation()
{
    var product = products[Math.floor(Math.random()*4)];
    if(product != curProduct)
        fadePage(product);  
        
    rotation = setTimeout("productRotation()", Math.floor(Math.random()*10000)+10000);
}

function fadePage(product)
{
    fadeOut = dojo.fadeOut({node: "page-fade",duration: 100});
    fadeIn = dojo.fadeIn({node: "page-fade",duration: 300});
    fadeOut.play();
    dojo.connect(fadeOut, "onEnd", function() {
        dojo.byId('page-'+curProduct).className = 'hide';
        dojo.byId('page-'+product).className = '';
        var tenth = products;
        if(dojo.indexOf(tenth, product) >-1)
        	dojo.byId('logo-10-th').className = '';
        else
        	dojo.byId('logo-10-th').className = 'hide';
        fadeIn.play();
        curProduct = product;
    });
}

function beginRotation()
{
    if(location.pathname=='/' || location.pathname=='/index.php') {
        menuSwapOff(curProduct)
        clearTimeout(rotation);
        rotation = setTimeout("productRotation()", Math.floor(Math.random()*10000)+10000);
        //alert(window.event.toElement.id)
    }
}

var slide;
var curSlide = 0;
var slideDuration = 600;
function doSlide(direction)
{
    nextSlide = curSlide + direction;
    
    if(nextSlide >=0 && nextSlide <webSamplePage) {
        gotoSlide(nextSlide);
        /*
        curSlide = nextSlide;
        dojo.fx.slideTo({node: "slide-obj",duration: slideDuration, left: (-1) * nextSlide * webSamplePageWidth}).play();
        */
    }
}

function swapImage(obj, image)
{
	if(obj.className !='dot') {
		src = obj.src.split('/');
		src[src.length-1] = image;
		obj.src = src.join('/');
	}
}

function gotoSlide(slide)
{
	nextSlide = slide;
    if(dojo.exists('s-'+curSlide)) {
        dojo.byId('s-'+curSlide).className = 'dot-button';
	    swapImage(dojo.byId('s-'+curSlide), 'bl_circle3.png');
    }
    dojo.fx.slideTo({node: "slide-obj",duration: slideDuration, left: (-1) * nextSlide * webSamplePageWidth}).play();
    curSlide = nextSlide;
    if(dojo.exists('s-'+curSlide)) {
        swapImage(dojo.byId('s-'+curSlide), 'bl_circle1.png');    
	    dojo.byId('s-'+curSlide).className = 'dot';
    }
}

var playedVideo = null;
function playViedo(name, file) {
    alert(name)
    dojo.byId(name).className = 'current';
    dojo.byId(currentVideo).className = ''; 
    videoPlay(name, file)    
}

function videoPlay(name, file)
{
    dojo.byId(name).className = 'current';
    dojo.byId(name+'-video').className = '';
    if(playedVideo!=null) {
        dojo.byId(playedVideo).className = ''; 
        dojo.byId(playedVideo+'-video').className = 'hide';
    }
    var width = 320;
    var height = 240;
	var so = new SWFObject('/public/swf/player.swf','player','320','240','9');
	so.addParam('allowfullscreen','false');
	so.addParam('allowscriptaccess','always');
	so.addParam('wmode','transparent');
	so.addParam('flashvars','file=/public/project/studio/vdo/'+file+'.flv&skin=/public/swf/overlay.swf&autostart=false&controlbar=over&stretching=exactfit&image=/public/swf/'+name+'.jpg&volume=40');
	so.write('player');      
    playedVideo = name;
}

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}


