$(document).ready(function(){
		$('#videoPlayer').jqm({trigger:'.load-video',closeClass:'jqmClose',modal:false,overlay:60,toTop:true,onShow:loadVideo,onHide:closeModal});
		$('#jqmPopup').jqm({trigger:'.load-ajax',closeClass:'jqmClose',modal:true,overlay:60,toTop:true,onShow:loadAjax,onHide:closeModal});
		$('.jqmClose').live('click',function()
		{
			$(this).parent().jqmHide();
		});
});


function loadVideo(hash)
{
	var vidTarget = "http://www.hcinteractive.com/Media_WebRoot/"+$(hash.t).attr('target').split(",")[0];
	var vidWidth = $(hash.t).attr('target').split(",")[1];
	var vidHeight = $(hash.t).attr('target').split(",")[2];
	$(hash.w).css({'height':0,'width':0,'display':'block'}).animate({'width':vidWidth,'margin-left':-(10+(vidWidth/2)),'height':vidHeight,'margin-top':-(10+(vidHeight/2))},200,'linear',function()
	{
		$(hash.w).html('<img class="jqmClose" src="images/close.png"><div id="video"><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><br/><br/><span style="color:white">This site requires Flash Player to view its multimedia content.</span></div>');
		var flashvars = {fileName:vidTarget};
		var params = {wmode:"opaque"};
		var attributes = {};
		myFlash = swfobject.embedSWF("flvplayer/hciplayer_"+vidWidth+vidHeight+".swf", "video", vidWidth, vidHeight, "9.0.0", "flash/expressInstall.swf", flashvars, params, attributes);
		$('#videoPlayer').focus();
	});
	//alert(vidTarget+": "+vidHeight+"x"+vidWidth);
	if ($.browser.msie)
	{
		if ($.browser.version == "6.0")
		{
			var offsetHeight = ((document.documentElement.clientHeight - vidHeight)/2);
			$(hash.w).css({'padding-top':'35px','position':'absolute','top':document.documentElement.scrollTop + offsetHeight});
			$('.jqmClose').css({'margin-top':'-25px','margin-left':'-25px'});
			setTimeout("$('.jqmClose').attr('src','images/close.gif');",100);
		}
	}
}

function loadAjax(hash)
{
	//alert($(hash.t).attr('target'));
	$(hash.w).load("/"+$(hash.t).attr('href')+' #wrap', function(response, status, xhr)
	{
		//alert('1. '+response+'\n2. '+status+'\n3. '+xhr.status+' '+xhr.statusText);
		$(hash.w).prepend('<img class="jqmClose" src="images/close.png">');
		//$(hash.w).css({'width':$(hash.w).innerWidth(),'height':$(hash.w).innerHeight()});
		while(hash.w.height() > ($(window).height() - 150))
		{
			hash.w.height((hash.w.height())-10);
		}
		$(hash.w).children('#wrap').height(hash.w.height());
		$(hash.w).children('#wrap').width(hash.w.width());
		$(hash.w).removeAttr("style").css({'z-index':9999,'margin-left':-(hash.w.width()/2),'margin-top':-(hash.w.height()/2),'display':'block'});
		return false;
	});

	setTimeout(function(){
		//alert('timeout');
		if($(hash.w).find('input[name=productspecid]').length != 0)
		{
			//alert('got an input hyar');
			$(hash.w).find('input[name=productspecid]').val($(hash.w).find('input[name=productspecid]').val()+','+$(hash.t).val());
		}
		if ($.browser.msie)
		{
			$('#jqmPopup').css('width',$(hash.w).children('#wrap').width());
			if ($.browser.version == "6.0")
			{
				var offsetHeight = ((document.documentElement.clientHeight - $(hash.w).height())/2);
				$(hash.w).css({'padding-top':'35px','position':'absolute','top':document.documentElement.scrollTop + offsetHeight});
			$('.jqmClose').css({'margin-top':'-25px','margin-left':'-25px'});
				$('.jqmClose').attr('src','images/close.gif');
			}
		}
	},500);
}

function closeModal(hash)
{
	if(($.browser.msie) && (($.browser.version == "7.0") || ($.browser.version == "6.0")))
	{
		window.location.reload(false);
	}
	$(hash.w).fadeOut('2000',function(){$(hash.o).remove();	$(hash.w).html('');});
	if($(hash.t).attr('name') == 'productspecid')
	{
		$(hash.t).attr('checked','checked');
	}
}

function cancelCEPurchase()
{
	$('#jqmPopup').find('input[name=productspecid]').val($('#jqmPopup').find('input[name=productspecid]').val().split(',')[1]);
	//alert($('#jqmPopup').find('input[name=productspecid]').val());
	$('#jqmPopup').find('input[type=submit]').click();
}
