// Our custom drag and drop implementation, extending YAHOO.util.DD
YAHOO.example.DDOnTop = function(id, sGroup, config) {
	YAHOO.example.DDOnTop.superclass.constructor.apply(this, arguments);
};
YAHOO.extend(YAHOO.example.DDOnTop, YAHOO.util.DD, {
	endDrag: function(e) {
		xpos = YAHOO.util.Dom.getX("draglayer");
		ypos = YAHOO.util.Dom.getY("draglayer");
		// add two pixels to accomodate for border
		setSearchBarCookie(xpos+2,ypos+2);
	}
});

var sbDrag;
// main call to YUI to set up draganddrop layer
(function() {
    YAHOO.util.Event.onDOMReady(function() {
        sbDrag = new YAHOO.example.DDOnTop("draglayer");
        sbDrag.setHandleElId("draghandle");
		resetBoundaries();
		sbDrag.startDrag = function(x,y){
			hideTip('tooltip');
		}
    });
})();

// custom to hide tooltip
function hideTip(tipId){
	var ht = new YAHOO.util.Element(tipId);
	ht.setStyle('display', 'none');
	setHideTipCookie("hide" + tipId);
}

// set bounding box for drag layer to screen res
function resetBoundaries(){
	sbDrag.clearConstraints();
	sbDrag.setXConstraint(YAHOO.util.Dom.getX("draglayer"),screen.width-YAHOO.util.Dom.getX("draglayer")-404);
	sbDrag.setYConstraint(YAHOO.util.Dom.getY("draglayer"),screen.height-YAHOO.util.Dom.getY("draglayer")-360);
}		
YAHOO.util.Event.addListener(
	window,
	"resize",
	function () {
		resetBoundaries();
	}
);	

// custom for show/hide of searchbox dashed border
function showborder(){
	var dl = new YAHOO.util.Element('draglayer');
	dl.setStyle('border', '2px dashed #f19000');
	// move left over by border width
	leftloc			= dl.getStyle('left');
	ml				= dl.getStyle('margin-left');
	if (leftloc=='50%'){
		ml 			= parseInt(ml.replace('px', ''));
		dl.setStyle('margin-left', (ml-2)+'px');
	}else{
		leftloc 	= parseInt(leftloc.replace('px', ''));
		dl.setStyle('left', (leftloc-2)+'px');
	}
	// move top up by border width
	toploc 			= dl.getStyle('top');
	toploc 			= parseInt(toploc.replace('px', ''));
	dl.setStyle('top', (toploc-2)+ 'px');
	/*
	var tt = new YAHOO.util.Element('tooltip');
	tt.setStyle('margin-top', '-2px');
	*/
}
function hideborder(){
	var dl = new YAHOO.util.Element('draglayer');
	dl.setStyle('border', 'none');
	// move left over by border width
	leftloc			= dl.getStyle('left');
	ml				= dl.getStyle('margin-left');
	if (leftloc=='50%'){
		ml 			= parseInt(ml.replace('px', ''));
		dl.setStyle('margin-left', (ml+2)+'px');
	}else{
		leftloc 	= parseInt(leftloc.replace('px', ''));
		dl.setStyle('left', (leftloc+2)+'px');
	}
	// move top up by border width
	toploc 			= dl.getStyle('top');
	toploc 			= parseInt(toploc.replace('px', ''));
	dl.setStyle('top', (toploc+2)+ 'px');
}