/**
  * Creately - http://creately.com
  * Copyright (C) 2009 Creately
  * URL: http://creately.com/
  *
  * Instructions: This JS is used to generate the embed HTML code to display
  * the embed Creately image.
  * 
  * Example usage:
  * <div id="creately-image" class="creately-diagram-embed"></div>
  * <script type="text/javascript" src="http://creately-nocookie.com/js/creately_embed_js_v1.js"></script>
  * <link href="http://creately-nocookie.com/css/creately_embed_css_v1.css" type="text/css" rel="stylesheet">
  * <script type="text/javascript">
  * new Creately.Embed_Widget({
  * id: 'creately-image',
  * diagid: 'fy737l1w1',
  * diagTitle: 'Diagram 1',
  * diagDesc: '',
  * editable: false,
  * width: 1500,
  * height: 1539,
  * });
  * </script>
  *
  * V1.0
  */

var Creately;
if (Creately == undefined) {
	Creately = {};
}

Creately.Embed_Widget = function( options )
{
	var container = document.getElementById( options.id );
	var htmlString = '';
	var directLinkPrefixh = "http://creately.com/app?diagID=";
	var imageLinkPrefixh = "http://create.ly/";

	var DEFAULT_SIZE = "Default Size";
	var HALF_SIZE = "Half Size";
	var THUMBNAIL_SIZE = "Thumbnail Size";
	var CUSTOM_SIZE = "Custom Size";
	
	var Thumb_Size = 60;
	
	if ( options.editable ) {
		htmlString = '\n<a class="creately-diagram-embed"';
		htmlString += ' href="' + directLinkPrefixh + options.diagid + '"';
		htmlString += ' title="Click to edit the diagram in Creately - you must be authorised by the owner">' 
	}
	
	htmlString += '\n<img class="creately-diagram-embed"';
	htmlString += ' src="' + imageLinkPrefixh + options.diagid + '"';

	if ( options.size == DEFAULT_SIZE ) {
		htmlString += ' height="' + container.height + '" width="' + container.width + '"';
	} else if ( options.size == HALF_SIZE ) {
		htmlString += ' height="' + ( container.height / 2 ) + '" width="' + ( container.width / 2 ) + '"';
	} else if ( options.size == THUMBNAIL_SIZE ) {
		htmlString += ' height="' + Thumb_Size + '" width="' + Thumb_Size + '"';
	} else {
		htmlString += ' height="' + options.height + '" width="' + options.width + '"';
	}
	
	htmlString += ' alt="' + options.diagTitle + ' - ' + options.diagDesc + ' - Powered by Creately - online diagramming and design"';
	htmlString += ' title="' + options.diagTitle + ' - ' + options.diagDesc + ' - Powered by Creately - online diagramming and design" />\n';
	
	
	if ( options.editable ) {
		htmlString += '</a>\n';
	}
	
	container.innerHTML = htmlString;
}
