function getScrollPosX(){
	var posX = (document.documentElement.scrollLeft || document.body.scrollLeft);
	return posX;
}

function getScrollPosY(){
	var posY = (document.documentElement.scrollTop || document.body.scrollTop);
	return posY;
}

function startIframe(url, width, height, left, top){
	var iframeDiv = document.getElementById("iframeDiv");
	if (width) {
		iframeDiv.style.width=width+"px";
		iframeDiv.style.height=height+"px";
		iframeDiv.style.left=left+"px";		
		iframeDiv.style.top=top+"px";		
	} else {
		iframeDiv.style.width="782px";
		iframeDiv.style.height="603px";
		iframeDiv.style.top="200px";	
	}4
	var iFrame = document.getElementById("iframe");
	// pass the parent url for cross domain communication
    var full_url=url + '#' + encodeURIComponent( document.location.href );    
	//alert("startIframe msgSink["+full_url+"]");
	iFrame.src=full_url;
	iframeDiv.style.display="block";	
}

function sendCloseOverlayMessage(change_to_url){
  var parent_url = decodeURIComponent( document.location.hash.replace( /^#/, '' ) ),link;
  //alert('CALLED CLOSE: change_to_url['+change_to_url+'] parent_url['+parent_url+'] parent['+parent+']');
  if(change_to_url){
    jQuery.postMessage('close_overlay,'+change_to_url, parent_url, parent );
  } else {
    jQuery.postMessage('close_overlay,', parent_url, parent );
  }
}

function sendResizeOverlayMessage(width,height){
  var parent_url = decodeURIComponent( document.location.hash.replace( /^#/, '' ) ),link;
  //alert('sendResizeOverlayMessage: parent_url['+parent_url+'] parent['+parent+'] width['+width+'] height['+height+']');
  jQuery.postMessage('resize_overlay,'+width+','+height, parent_url, parent );
}

//alert('registering jQuery.receiveMessage');
jQuery.receiveMessage(
    function(e){
      if(e.data){
        //alert("receiveMessage fired " + e.data);
        var splitted = e.data.split(',');
        if(splitted.length>0){
          var op = splitted[0];
          if ( op === 'close_overlay' ) {
            if(splitted.length==1){
              closeOverlay();
            }
            if(splitted.length==2){
              var change_to_url=splitted[1];
              closeOverlay(change_to_url);
            }
          }
          if ( op === 'resize_overlay' ) {
            if(splitted.length==3){
              var width = splitted[1];
              var height = splitted[2];
              resizeOverlaySmall(width, height)
            }
          }
        }
      }
    }
);
