var docLimit = 3;


var docFlip = function(showDoc)
{
	if(showDoc)
	{
		var boolString = 'false';
		$('docFlipAnchor').update('More');
	}
	else
	{
		var boolString = 'true';
		$('docFlipAnchor').update('Less');
	}
	$('docFlipAnchor').href = 'javascript:docFlip(' + boolString + ')';
	var downCount = 1;
	$$('.downloadText p').each(function(downEl)
	{
		if(downCount > docLimit)
		{
			if(showDoc)
			{
				downEl.hide();
			}
			else
			{
				downEl.show();
			}
		}
		downCount++;
	});
};

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");

jQuery(document).ready(function()
{
	if($$('.downloadText p').size() > 0)
	{
		$$('.downloadText').each(function(downEl)
		{
			downEl.insert({top: '<a id="titleD">Relevant Documents</a>'});
		});
	}
	if($$('.downloadText p').size() > docLimit)
	{
		$$('.downloadText').first().insert({bottom: '<a id="docFlipAnchor"></a>'});
		docFlip(true);
	}
	//<![CDATA[
	/* Replacement calls. Please see documentation for more information. */

	//]]>
	if(!frontend)
	{
		//theme_advanced_resizing : true,
		//document_base_url : "http://www.wirebox.us/",
		tinyMCE.init(
		{
			mode : "none",
			editor_selector : "mceEditor",
			theme : "advanced",
			plugins : "filemanager,imagemanager,autoresize,safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,spellchecker,addcolumn",
			theme_advanced_buttons1 : "insertfile,insertimage,advimage,imagemanager,bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,nonbreaking,cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist",
			theme_advanced_buttons2 : "blockquote,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor,|,charmap,iespell,media,advhr",
			theme_advanced_layout_manager : "SimpleLayout",
			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,strikethrough",
			theme_advanced_buttons4 : "styleselect,formatselect,fontselect,fontsizeselect,|,undo,redo,|,spellchecker",
			theme_advanced_toolbar_location : "external",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			relative_urls : false,
			auto_resize : true,
			theme_advanced_resizing : true,
			theme_advanced_resize_horizontal : false,
			content_css : "/custom/css/style.css",
			extended_valid_elements : "iframe[height|width|src|frameborder|scrolling]"
		});
		tinymce.create('tinymce.plugins.addcolumn',
		{
			init : function(ed, url)
			{
				ed.addButton('addcolumn',
				{
					title : 'Add Column',
					image : url + '/youtube.png',
					onclick : function()
					{
						//idPattern = /(?:(?:[^v]+)+v.)?([^&=]{11})(?=&|$)/;
						//var vidId = prompt("YouTube Video", "Enter the id or url for your video");
						//var m = idPattern.exec(vidId);
						//if (m != null && m != 'undefined')
							var newCode = '';
							newCode += '<div style="background: #CCC; width: 300px; overflow: scroll; overflow-y : hidden;">';
							newCode += ' <table>';
							newCode += '   <tr>';
							newCode += '    <td nowrap></td>';
							newCode += '  </tr>';
							newCode += ' </table>';
							newCode += '</div>';

							newCode = '<div class="col_1-3"><h1>test</h1></div>';
							ed.execCommand('mceInsertContent', false, newCode);
					}
				});
			},
			createControl : function(n, cm)
			{
				return null;
			},
			getInfo : function()
			{
				return {
						longname : "Add Column",
						author : 'Wirebox',
						authorurl : 'http://www.wirebox.co.uk/',
						infourl : 'http://www.wirebox.co.uk/',
						version : "1.0"
				};
			}
		});
		tinymce.PluginManager.add('addcolumn', tinymce.plugins.addcolumn);
		textAreas.each(function(txtEl)
		{
			//alert ("elis - '"+txtEl+ "'");
			tinyMCE.execCommand('mceAddControl', false, txtEl);
		});
	}

});
