/**
 * @author kasey mccurdy & slash/web studios for meredith corporation
 * www.slashwebstudios.com
*/
jQuery.noConflict();


var mdp_showFlashAppModal = function(swf,width,height,name,div){
	jQuery("#mdp_overlay").remove();
	jQuery("body").append("<div id='mdp_overlay'>"+
						"<div id='mdp_content'>"+
						"<div id='mdp_content_body'><div id='mdp_flash'></div><div id='mdp_content_close'></div></div>"+
						"</div>"+
						"</div>");
						
						
	
	jQuery("#mdp_overlay").css({
		'height':jQuery(document).height()+"px",
		'width':jQuery(document).width()+"px",
		'background':'url(/public/images/calculators/bg_black_trans.png) repeat',
		'top':0,
		'left':0,
		'position':'absolute',
		'zIndex':'9999999',
		'display':'none'
	});	

	jQuery("#mdp_overlay").fadeIn();
	if(!jQuery.browser.safari){
		jQuery("#mdp_overlay").click(function(){jQuery("#mdp_overlay").remove();});
	}
	
	jQuery("#mdp_content").css({'width':(width+50)+"px",
							'zIndex':'99999999',
							"float":"left",
							"position":"relative",
							'height':(height+50)+"px",
							'padding':'40px',
							'background':'url(/public/images/calculators/bg.png) no-repeat',
							'marginLeft':(jQuery(window).width()-width)/2+"px",
							'marginTop':(jQuery(window).height()-height)/2+"px"
							});
	jQuery("#mdp_content_body").css({'zIndex':'999999999','background':'url(/public/images/calculators/ajaxspinner.gif) no-repeat 15px 15px','width':'100%','height':'100%'});
							
	jQuery("#mdp_content_close").css({'position':'absolute',
									'background':'url(/public/images/calculators/x.png) no-repeat',
									'top':'20px',
									'cursor':'pointer',
									'zIndex':'999999',
									'right':'65px',
									'width':'40px',
									'height':'40px'
							});
	
	jQuery("#mdp_content_close").click(function(){jQuery("#mdp_overlay").remove()});
	
	setTimeout(function(){
		var flashvars = {};
		var params = {'wmode':'transparent'};
		var attributes = {};
		attributes.id = name;
		swfobject.embedSWF(swf, div, width, height, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
	},2000);
	
	//bind to the resize event to resize the background
	jQuery(window).resize(function(){
		jQuery("#mdp_overlay").css({'height':jQuery(document).height()+"px",
							'width':jQuery(document).width()+"px"
							});	
		jQuery("#mdp_content").css({'marginLeft':(jQuery(window).width()-width)/2+"px",
							'marginTop':(jQuery(window).height()-height)/2+"px"
							});
	});
}

var setupClicks = function(){
	jQuery("a.mdp_calc_bmi_link").click(function(){
		scroll(0,0);
		mdp_showFlashAppModal(base+"public/images/calculators/mdp_d_bmi.swf",485,339,"mdp_bmi_quiz","mdp_flash");
	});
	jQuery("#mdp_calc_bmi").click(function(){
		scroll(0,0);
		mdp_showFlashAppModal(base+"public/images/calculators/mdp_d_bmi.swf",485,339,"mdp_bmi_quiz","mdp_flash");
	});
	jQuery("a.mdp_calc_thr_link").click(function(){
		scroll(0,0);
		mdp_showFlashAppModal(base+"public/images/calculators/mdp_d_thr.swf",485,339,"mdp_thr_quiz","mdp_flash");
	});
	jQuery("#mdp_calc_thr").click(function(){
		scroll(0,0);
		mdp_showFlashAppModal(base+"public/images/calculators/mdp_d_thr.swf",485,339,"mdp_thr_quiz","mdp_flash");
	});
	jQuery("a.mdp_calc_calories_link").click(function(){
		scroll(0,0);
		mdp_showFlashAppModal(base+"public/images/calculators/mdp_d_calories.swf",485,339,"mdp_calories_quiz","mdp_flash");
	});
	jQuery("#mdp_calc_calories").click(function(){
		scroll(0,0);
		mdp_showFlashAppModal(base+"public/images/calculators/mdp_d_calories.swf",485,339,"mdp_calories_quiz","mdp_flash");
	});
	jQuery("#mdp_carb_counter").click(function(){
		scroll(0,0);
		mdp_showFlashAppModal(base+"public/images/calculators/mdp_d_carbcounter.swf",485,339,"mdp_calories_quiz","mdp_flash");
	});
}


jQuery(document).ready(function(){
	setupClicks();
});
