
function showStar(divId){
  ContentObj = document.getElementById(divId);
  if( ContentObj) {
  	if (YAHOO.util.Dom.getStyle(ContentObj,'display') == 'none') {
  	    //YAHOO.util.Dom.setStyle(ContentObj, 'height', 0);
		YAHOO.util.Dom.setStyle(ContentObj, 'display', 'block'); 
		YAHOO.util.Dom.setStyle(ContentObj, 'zindex', 999); 
    	var animator = new YAHOO.util.Anim(ContentObj,{opacity:{to:1},height:{to:80}});
		animator.animate();	
	 }	
   }
}

function hideStar(divId){
  ContentObj = document.getElementById(divId);
  if( ContentObj) {
  	if (YAHOO.util.Dom.getStyle(ContentObj,'display') != 'none') {
  	    var animator = new YAHOO.util.Anim(ContentObj,{opacity:{to:0},height:{to:0}});
  	    animator.onComplete.subscribe(function(){YAHOO.util.Dom.setStyle(divId, 'display', 'none');});
		animator.animate();	
    }
  }
}

/*
	Set the form input fields for the star location.
*/
function setStarPoint(x,y){
	xCoordObj = document.getElementById('xcoord');
	yCoordObj = document.getElementById('ycoord');
	
	xCoordObj.value = x;
	yCoordObj.value = y;
}

/*
	Move the star in the selected location.
*/
function placeNewStar(x,y){
	newStarObj = document.getElementById('dragdrop');
	YAHOO.util.Dom.setStyle(newStarObj, 'position', 'absolute');
	YAHOO.util.Dom.setStyle(newStarObj, 'top', y);
	YAHOO.util.Dom.setStyle(newStarObj, 'left', x);
}

/*
	Move the star to its original location.
*/
function resetStar(Id){
	ddObj     = YAHOO.util.DragDropMgr.getDDById(Id);
	regionObj = YAHOO.util.DragDropMgr.getLocation(ddObj);   
    domObj    = regionObj.getElement(Id);
    
//    xy        = regionObj.getSavedXY();
	YAHOO.util.Dom.setStyle(Id, 'left', 370);
	YAHOO.util.Dom.setStyle(Id, 'top',  450);
	
	regionObj.initConstraints();
}

/*
	Define the region for DragDrop operations.
*/
(function() {
    var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event,
        dd1;


    YAHOO.example.DDRegion = function(id, sGroup, config) {
        this.cont = config.cont;
        YAHOO.example.DDRegion.superclass.constructor.apply(this, arguments);
    };

    YAHOO.extend(YAHOO.example.DDRegion, YAHOO.util.DD, {
        cont: null,
        savexy: null,
        init: function() {
            //Call the parent's init method
            YAHOO.example.DDRegion.superclass.init.apply(this, arguments);
            //Get the element we are working on and save its original position
            var el = this.getEl();
            savexy = Dom.getXY(el);

            this.initConstraints();
        },
        initConstraints: function() {
            //Get the top, right, bottom and left positions
            var region = Dom.getRegion(this.cont);

            //Get the element we are working on
            var el = this.getEl();

            //Get the xy position of it
            var xy = Dom.getXY(el);

            //Get the width and height of the star
            var width = parseInt(Dom.getStyle(el, 'width'), 10);
            var height = parseInt(Dom.getStyle(el, 'height'), 10);

            //Set left to x minus left, adjust for picture size/design placement
            var left = xy[0] - region.left + width/2;

            //Set right to right minus x minus width
            var right = region.right - xy[0] - width*.75;

            //Set top to y minus top
            var top = xy[1] - region.top + height/2;

            //Set bottom to bottom minus y minus height - way too low, overwritten 
						var bottom = -100;
            //var bottom = region.bottom - xy[1] - height*2;

            //Set the constraints based on the above calculations
            this.setXConstraint(left, right);
            this.setYConstraint(top, bottom);

         //   Event.on(window, 'resize', function() {
         //       this.initConstraints();
         //   }, this, true);
        },
		getSavedXY: function(){
			return savexy;
		},
		
		startDrag: function(x, y) {
			//YAHOO.log(this.id + " startDrag", "info", "script.js");

			var style = this.getEl().style;

			// store the original z-index
			this.origZ = style.zIndex;

			// The z-index needs to be set very high so the element will indeed be on top
			style.zIndex = 999;
		},

		onMouseUp: function(e) {
            //Get the top, right, bottom and left positions
            var region = Dom.getRegion(this.cont);

            //Get the element we are working on
            var el = this.getEl();

			//Get the xy position of it
			var xy = Dom.getXY(el);
			x = xy[0] - region.left; 
			y = xy[1] - region.top;
			
			// get the width and height of the element
			 width  = parseInt(Dom.getStyle(el, 'width'));
			 height = parseInt(Dom.getStyle(el, 'height'));
			
			// offset to center the image on the selected point
			// x -= (width/2);			
			// y -= (height/2);

			// make sure we are in the region's top and left boundaries
			// x = x < 0 ? 0 : x;
			// y = y < 0 ? 0 : y;
		
			// make sure we are in the region's bottom and right boundaries
			 x = x > 800 ? 800 - (width/2) : x;
			 y = y > 450 ? 450 - (height/2) : y;

			setStarPoint(x,y);
		//	placeNewStar(x,y);
		}

    });

    Event.onDOMReady(function() {
        dd1 = new YAHOO.example.DDRegion('dragdrop', '', { cont: 'theScene'});
    });

})();



