	
	function intervalFunc(val){
		clearInterval();
		rotatCurr=val;
		updateMainDiv();
		updatePlayButtons();
		homeMainRotation(val);
	}
	
	function clearInterval(){
		try{ clearTimeout(timeOut); }catch(eeee1){	}
		try{ clearInterval(intVar);	}catch(eeee2){	}
	}
	
	function homeMainRotation (setFrame)
	{
    	//alert(rotatCurr);
    	
		clearInterval();    	
    	
    	if (setFrame==null){
    		rotatCurr++;
    	}else{
    		rotatCurr=setFrame;
    	}
    	rotateNumber();
  	   
    	var waittime = generalWaitime;    	
    	if(rotatCurr==2){waittime=80000;} //for 2
    	timeOut=setTimeout ( "homeMainRotation()", waittime );
    	
		updateMainDiv();
    	updatePlayButtons();

    	//alert(rotatCurr);
		
    	rotatNum++;    	
	}

	function updateMainDiv(){		
		for(var i=rotatStart; i<=rotatEnd; i++){
			if (i==rotatCurr){
				document.getElementById("divM"+i).style.display='inline';
			}else{
				document.getElementById("divM"+i).style.display='none';
			}
		}		
	}
	
	function rotateNumber(){
		if (rotatCurr >rotatEnd ){
			rotatCurr = rotatStart;
		}else if(rotatCurr<rotatStart){
			rotatCurr = rotatEnd;
		}else{
			
		}	
	}
	
	
	function updatePlayButtons(status){	
		try{
			document.getElementById("playButtonsL").innerHTML = "<img src=\"images/mprev.gif\" style=\"cursor:pointer;\" onclick=\"playMain('prev')\" title=\"go to previous scene\" />";
			document.getElementById("playButtonsR").innerHTML = "<img src=\"images/mnext.gif\" style=\"cursor:pointer;\" onclick=\"playMain('next')\" title=\"go to next scene\" />";
			if (status=="stop"){
				document.getElementById("playButtonsM").innerHTML = "<img src=\"images/mplay.gif\" style=\"cursor:pointer;\" onclick=\"playMain('play')\" title=\"start scene rotation\" />";
			}else{
				document.getElementById("playButtonsM").innerHTML = "<img src=\"images/mstop.gif\" style=\"cursor:pointer;\" onclick=\"playMain('stop')\" title=\"stop scene rotation\" />";
			}
			document.getElementById("nowPlaying").innerHTML = "NOW PLAYING : &nbsp;&nbsp; " + rotatArr[rotatCurr-1] + "";
		}catch(eee2){}
	}
	
	function playMain(status){ //prev, next, stop, play
		var ss = "";
		if(status=="prev"){
			rotatCurr = rotatCurr-1;
			rotateNumber();
			intervalFunc(rotatCurr);
		}else if (status=="next"){
			rotatCurr = rotatCurr+1;
			rotateNumber();
			intervalFunc(rotatCurr);
		}else if (status=="stop"){
			clearInterval();
			ss = "stop";
		}else if (status=="play"){
			intervalFunc(rotatCurr);
		}else{
		}
		
		updatePlayButtons(ss);
	}
	

	
    /* Use the Google AJAX Libraries API:
        http://code.google.com/apis/ajaxlibs/ */

	google.load("swfobject", "2.1");


	  function updateHTML(elmId, value) {
	    //document.getElementById(elmId).innerHTML = value;
	  }
	
	  function setytplayerState(newState) {
	    //updateHTML("playerstate", newState); //0:completed playing; 1:playing;  2:pause; 3:seeking;  5:waiting
	  }
	
	  function onYouTubePlayerReady(playerId) {
	    ytplayer = document.getElementById("myytplayer");
		setInterval(updateytplayerInfo, 250);
		updateytplayerInfo();
		ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
		ytplayer.addEventListener("onError", "onPlayerError");
		
		if (rotatNum==1) {playYoutube(); rotatNum++;}
		//resumed on each rotation
	  }
	
	  function onPlayerError(errorCode) {
	    alert("An error occured: " + errorCode);
	  }
	
	  var timeOut;
	  function onytplayerStateChange(newState) {
	    setytplayerState(newState);
	    
	    clearInterval();	
    	
    	if (newState==0 ){
    		timeOut=setTimeout("intervalFunc(2)", 5000);//intervalFunc(1);
    	}else if(newState==2){
    		intervalFunc(1);
    	}else if(newState==5){
    		intervalFunc(1);
    	}else{
    		
    	}
	    
	    
	  }
	
	  function updateytplayerInfo() {
		  /*
	    updateHTML("bytesloaded", getBytesLoaded());
		updateHTML("bytestotal", getBytesTotal());
		updateHTML("videoduration", getDuration());
		updateHTML("videotime", getCurrentTime());
		updateHTML("startbytes", getStartBytes());
		updateHTML("volume", getVolume());
		*/
	  }
	
	  // functions for the api calls
	  function loadNewVideo(id, startSeconds) {
	    if (ytplayer) {
	      ytplayer.loadVideoById(id, parseInt(startSeconds));
	    }
	  }
	
	  function cueNewVideo(id, startSeconds) {
	    if (ytplayer) {
	      ytplayer.cueVideoById(id, startSeconds);
	    }
	  }
	
	  function playYoutube() {
	    if (ytplayer) {
	      ytplayer.playVideo();
	    }
	  }
	
	  function pause() {
	    if (ytplayer) {
	      ytplayer.pauseVideo();
	    }
	  }
	
	  function stop() {
	    if (ytplayer) {
	      ytplayer.stopVideo();
	    }
	  }
	
	  function getPlayerState() {
	    if (ytplayer) {
	      return ytplayer.getPlayerState();
	    }
	  }
	
	  function seekTo(seconds) {
	    if (ytplayer) {
	      ytplayer.seekTo(seconds, true);
	    }
	  }
	
	  function getBytesLoaded() {
	    if (ytplayer) {
	      return ytplayer.getVideoBytesLoaded();
	    }
	  }
	
	  function getBytesTotal() {
	    if (ytplayer) {
	      return ytplayer.getVideoBytesTotal();
	    }
	  }
	
	  function getCurrentTime() {
	    if (ytplayer) {
	      return ytplayer.getCurrentTime();
	    }
	  }
	
	  function getDuration() {
	    if (ytplayer) {
	      return ytplayer.getDuration();
	    }
	  }
	
	  function getStartBytes() {
	    if (ytplayer) {
	      return ytplayer.getVideoStartBytes();
	    }
	  }
	
	  function mute() {
	    if (ytplayer) {
	      ytplayer.mute();
	    }
	  }
	
	  function unMute() {
	    if (ytplayer) {
	      ytplayer.unMute();
	    }
	  }
	  
	  function getEmbedCode() {
	    alert(ytplayer.getVideoEmbedCode());
	  }
	
	  function getVideoUrl() {
	    alert(ytplayer.getVideoUrl());
	  }
	  
	  function setVolume(newVolume) {
	    if (ytplayer) {
	      ytplayer.setVolume(newVolume);
	    }
	  }
	
	  function getVolume() {
	    if (ytplayer) {
	      return ytplayer.getVolume();
	    }
	  }
	
	  function clearVideo() {
	    if (ytplayer) {
	      ytplayer.clearVideo();
	    }
	  }
          

	function getDetails(obj){ 
		alert('event');

		clickX = window.event.x-obj.offsetLeft-document.getElementById("divM1").offsetLeft; 
		clickY = window.event.y-obj.offsetTop-document.getElementById("divM1").offsetTop;     
		//clickX = event.offsetX?(event.offsetX):event.pageX-document.getElementById("divM1").offsetLeft;
		//clickY = event.offsetY?(event.offsetY):event.pageY-document.getElementById("divM1").offsetTop;
	    
		alert(clickX + "-" + clickY);
		
		if(clickX>=495 && clickX<=522 && clickY>=562 && clickY<=584 ){
			intervalFunc();
		}
	} 

	
	function getyoutubeString(autoPlayVal){
		var youtubeString = "<object width=\"590\" height=\"369\">"+
			"<param name=\"movie\" value=\"http://www.youtube.com/v/WSQH3b_Z_tE&hl=en&fs=0&hd=1&autoplay="+autoPlayVal+"&rel=0&showsearch=0\"></param>"+
			"<param name=\"allowscriptaccess\" value=\"always\"></param>"+
			"<param name=\"allowFullScreen\" value=\"false\" />"+
			"<param name=\"wmode\" value=\"transparent\">"+
			"<embed src=\"http://www.youtube.com/v/WSQH3b_Z_tE&hl=en&fs=0&hd=1&autoplay="+autoPlayVal+"&rel=0&showsearch=0\""+
			"	type=\"application/x-shockwave-flash\" wmode=\"transparent\" allowscriptaccess=\"always\" allowFullScreen=\"false\""+
			"	width=\"590\" height=\"369\"></embed>"+
			"</object>";
		
		return youtubeString;
	}
	
	