isIE6 = $.browser.msie && ($.browser.version == "6.0");

$(document).ready(function(){
	$('.qd_pop_link').click(function(){
		$('.qd_pop').show();				 
	});
	
	$('.qd_close_link').click(function(){
		$('.qd_pop').hide();				 
	});
	
	$('.jqmWindow').jqm();
	
	$('.pd_pop_image').click(function(){
		var targs = $('#pd_img').attr('src').split(".");
		var targ_src = targs[0] + "_large." + targs[1];
		showModalImage(targ_src);			 
	});
	
	$('.pd_pop_view').click(function(){
		var targ_src = $(this).attr('href');
		showModalImage(targ_src);
		return false;
	});
	
	var hra_rand = Math.floor(Math.random()*4) + 1;
	$('#home_reason_ad').attr("src","images/HP_Reason_" + hra_rand + ".png");
	
});

function showModalImage(img_src){
	
var img = new Image();
$(img).load(function () {
	$('#modal_content').html('');
	$('#modal_content').append(this);
	var targ_left = (img.width / 2) * -1;
	$('.jqmWindow').css({'margin-left': targ_left});
	if(!isIE6)
	{
		var targ_top = (img.height / 2) * -1;
		$('.jqmWindow').css({'margin-top': targ_top});
	}
	$('.jqmWindow').jqmShow();
})
.error(function () {
  alert('error');
  // notify the user that the image could not be loaded
})
.attr('src', img_src);

}
