// Created 4/15/2010 10:33:56 AM
// Purpose: Consolidate all JQuery Code used by Offers in Test&Target
// Secondary Purpose: All sitewide on dom load JQuery To be consolidated here
$.noConflict();

// Lightbox replacement code
(function($){$(document).ready(function(){
			$("[rel=lightbox][href*=.]").colorbox({initialWidth:"50",initialHeight:"50",transition:"elastic",rel:"nofollow",opacity:"0.70",onComplete:function(){$('#cboxLoadedContent').css('margin-top','15px');}});
			});
})(jQuery);

// Utility function to show page mboxes
// Usage: $(document).ready(OutlineMbox);
function OutlineMbox()
{
	(function($){
		var tmp=$('[class=mboxDefault]').css({'cursor':'move','border':'0px solid blue','overflow':'visible','z-index':'1000'});
		tmp.each(function(ix){ var $tmp2=$('[class=mboxDefault]:eq('+ix+')');var $tmp3=$tmp2.parent('td');var $mName=$tmp2.next().get(0).innerHTML.replace('\');','').replace('mboxCreate(\'','').replace('mboxCreate(\"','').replace('\");','');if ($tmp3.length>0){ $tmp2.css({'height':$tmp3.css('height'),'width':$tmp3.css('width')});};$tmp2.prepend('<div class="mboxInfo" style="border:1px dashed black;position:absolute;text-align:left;"><div style="width:100%;height:100%;opacity:0.40;filter:alpha(opacity=40);background-color:#ccc;position:absolute;top:0px;z-index:1001;"></div><span onclick="EditDefault(this);" style="cursor:pointer;opacity:1.0;filter:alpha(opacity=100);padding:4px;top:0px;font-size:12px;font-weight:normal;position:relative;color:#0f0;background-color:#333;font-family:arial;text-align:left;z-index:1002;" mName="'+$mName+'">'+$mName+'&nbsp;<span class="mboxInfoDim" style="color:red;">'+$tmp2.width()+'px x '+$tmp2.height()+'px</span></span></div>\r\n<!-- End mboxInfo -->\r\n\r\n');});
		
		$('body').css({'margin-top':'10px','margin-bottom':'10px'});
		var tmpBody=$('#containerInner').css({'border':'1px solid black'});
		if (tmpBody.length==0)
		{
			$('table:eq(0)').css({'border':'1px solid black'});
		}
		var tmpInfo=$('.mboxInfo');
		tmpInfo.each(function(ix){ var $tmp2=$('.mboxInfo:eq('+ix+')');var $tmp3=$tmp2.parent();$tmp2.width($tmp3.width());$tmp2.height($tmp3.height()); });
		tmpInfo.draggable().resizable().resize(function(){ $('.mboxInfo').each(function(ix){ var $tmp2=$('.mboxInfo:eq('+ix+')');var $tmp3=$tmp2.width()+'px x '+$tmp2.height()+'px';$tmp2.find('span:eq(1)').text($tmp3); });});
		
		// Move jsonly mboxes
		$('.mboxInfo:contains(jsonly)').css({'left':'-10px','height':'17px','width':'auto'}).resize();
		CreateEditDialog();
		InitEditDialog();
	})(jQuery);
}
function CreateEditDialog()
{
/*
<div id="mboxDevTools" style="opacity:0.90;filter:alpha(opacity=90);" title="Mbox Development Tools" class="ui-widget-content">
	<div id="accordion">
		<h3>
			<a href="#">
				HTML 
			</a>
		</h3>
		<div>
			<p>
				Mbox Name: 
				<span id="abeditboxlabel">
				</span>
			</p>
			<p>
				<textarea id="abeditbox" style="overflow:scroll;overflow-y: scroll;overflow-x: hidden;overflow:-moz-scrollbars-vertical;width:249px;height:122px;"></textarea> 
			</p>
		</div>
		<h3>
			<a href="#" onclick="$(\"#abpreviewbox\").html($(\"#abeditbox\").val()).draggable();">
				Preview 
			</a>
		</h3>
		<div>
			<p>
			<div id="abpreviewbox" style="cursor:move;">
			</div>
			</p>
		</div>
		<h3>
			<a href="#">
				Operations 
			</a>
		</h3>
		<div>
			<p>
				<input type="button" value="Apply" />
			</p>
			<ul>
				<li>
					List item one 
				</li>
				<li>
					List item two 
				</li>
				<li>
					List item three 
				</li>
			</ul>
		</div>
		<h3>
			<a href="#">
				Notes 
			</a>
		</h3>
		<div>
			<p>
				<textarea id="abeditbox_notes"></textarea> 
			</p>
		</div>
	</div>
</div>
*/
	(function($)
	{
		var theTarget=$('#mboxDevTools');
		if (theTarget.length==0)
		{
			var theHTML='<div id="mboxDevTools" style="opacity:0.90;filter:alpha(opacity=90);" title="Mbox Development Tools" class="ui-widget-content"><div id="accordion"><h3><a href="#"> HTML </a></h3><div><p>Mbox Name: <span id="abeditboxlabel"> </span></p><p><textarea id="abeditbox" style="overflow:scroll;overflow-y: scroll;overflow-x: hidden;overflow:-moz-scrollbars-vertical;width:249px;height:122px;"></textarea></p></div><h3><a href="#" onclick="(function($){$(\'#abpreviewbox\').html($(\'#abeditbox\').val()).draggable();})(jQuery);"> Preview </a></h3><div><p><div id="abpreviewbox" style="cursor:move;"></div></p></div><h3><a href="#"> Operations </a></h3><div><p><input type="button" value="Apply" onclick="jQuery(\'#abeditbox:first\')[0].targetEl.innerHTML=jQuery(\'#abeditbox:first\')[0].value;" /> <input type="button" value="Undo" /></p></div><h3><a href="#"> Notes </a></h3><div><p><textarea id="abeditbox_notes"></textarea></p></div></div></div>';
			$('body').append(theHTML);
		}
	})(jQuery);
}	
function InitEditDialog()
{
	(function($){
			$("#accordion").accordion({
				fillSpace: true
			});
			$("#mboxDevTools").dialog({
				autoOpen: false
				,show: 'slide'
				,hide: 'slide'
				,resize: function() {
		 			$("#accordion").accordion("resize");  
		 			var _abeBox=$("#abeditbox");
		 			var _par=_abeBox.closest("div");
		 			_abeBox.width(_par.width());
		 			_abeBox.height(_par.height()-50);
		 		}
		 		,height:340
		 		,width:336
			}).css('overflow','hidden');
	})(jQuery);
}
function EditDefault(theEl)
{
	(function($)
	{
		var theD=$('#mboxDevTools');
		if (! theD.dialog('isOpen')){ theD.dialog('open');}
		$("#accordion").accordion('activate',0);
		var theTarget=$('#abeditbox:first');
		if (theTarget.length==0)
		{
			$('body').append('<textarea id="abeditbox" onchange="this.targetEl.innerHTML=this.value;" style="font-family:monaco;font-size:9pt;position:absolute;border:solid 5px gray;" rows="20" cols="100"></textarea>');
			theTarget=$('#abeditbox:first').draggable().resizable();
		}
		$('#abeditboxlabel').text(theEl.getAttribute('mName'));
		theTarget[0].targetEl=theEl.parentNode.parentNode;
		theTarget[0].value=theEl.parentNode.parentNode.innerHTML;
		
	})(jQuery);
}

// Serves alternate content for campaign im_check_aisle_ab
function ABHideLearnMore()
{
	var theBtn='/fsg/images/btn_get_started_blue.gif';
	if (arguments && arguments.length > 0)
	{
		theBtn=arguments[0];
	}
	(function($)
	{
		var tmp=$('[class=mainContentItemRight]');
		tmp.each(function(ix){ var $tmp2=$('[class=mainContentItemRight]:eq('+ix+')');
			if ($tmp2.children('a').length > 1)
			{
				$tmp2.children('a').first().css('display','none');
			}
			else if ($tmp2.children('a').length==1)
				{
					$tmp2.children('a').first().children('img').first().attr('src',theBtn);
				}
			});
		var temp2=$('a[name$=Order] > img').attr('src',theBtn);
		var temp3=$('.mainItemTotalPrice').css('color','#666666');
	})(jQuery);
}

