var modal = false;
var page = "home";

/*$.support.positionFixed = (function(){ 
    var elem = $('<div>',{
            css : {
                position:   'fixed',
                top:        '42px',
                visibility: 'hidden'
            }
        }).appendTo(document.body || document.documentElement),
        
        // also account for page scroll
        support = parseInt(elem.offset().top,10) - (document.body ? document.body.scrollTop : 0) === 42;
        
    elem.remove(); 
    return support; 
})();*/

$(document).ready(function() {

	//if (!$.support.positionFixed) return;
	if ($.browser.msie && $.browser.version.substr(0,1)<7) return;
	
	//if (hideadbar) return;
	
	$('body').css('margin-bottom','-81px');
	$("head").append("<link>");
    css = $("head").children(":last");
    css.attr({
      rel:  "stylesheet",
      type: "text/css",
      href: "/adbar/adbar-dm.css"
    });

    if (modal) {
	    $.getScript("/adbar/jquery.simplemodal-1.3.5.min.js", function(){});
    }
	/*<a href="http://dishwashermagic.com/where-to-buy.php">*/
	if (modal && home) $('body').append('<div id="adbar-iframe-container"><div id="adbar-iframe-close"><a href="#close-adbar-iframe"><img id="wtb_page" src="" /></a></div></div>');
	$("body").append('<div id="adbar"><a style="z-index: 9999;" href="http://www.whatslurking.com" target="_blank"><img src="/adbar/images/whatlurks_ad.png" /><a href="#close-adbar"><img id="adbar-closebutton" src="/adbar/images/sum023_closebtn.png" /></a></div></a>');
	
	//$('#adbar-iframe-container').append('<iframe id="adbar-iframe" height="100%" width="100%" scrolling="auto" frameborder="0" />');
	
	// Close Button
	$("#adbar a[href='#close-adbar']").click(function () {
		// Slide down quickly
		$("#adbar").animate({
			'bottom': '-=81px'
		}, 250, function() {
			// hide when it's out of sight
			$("#adbar").hide();
		});
		return false;
	});

//$("#adbar-link").nyroModal({type:'div', bgColor: '#000000', windowResize: true, autoSizable: true, closeButton: '<a href="#" class="nyroModalClose" id="adbar-iframe-close" title="close"><img src="closebox.png" /></a>'});
	
	//$.nyroModalSettings();
	
	/*$("#adbar #adbar-link").click(function () {
		//$.nyroModalSettings({minWidth: 600});
		$('iframe').load(function()
				{
					//$(document).trigger('iframecheck');
					//doIframe();
				}
			);
	});
	*/
	if (modal) {
		$("#adbar .adbar-link").click(function () {
			//$("#adbar-iframe-container").fadeIn('fast');
			
			if ($("#adbar-iframe").length == 0) {
				$('#adbar-iframe-container').append('<iframe id="adbar-iframe" height="81px" width="900px" scrolling="auto" style="display:none;" frameborder="0" />');
				//$("#adbar-iframe").attr('src', 'test1.html');
			}
			
			$("#adbar-iframe-close a").click(function() {
				$("#adbar-iframe-container").fadeOut('fast', function() {
					$.modal.close();
				});
				return false;
				
				});
			
			
			//$("#adbar-iframe").show();
			//iframeResize();
			/*$("#adbar-iframe").ready(function () {
				$("#adbar-iframe").fadeIn('fast');
			});*/
			//$("#adbar-iframe").trigger('load');
			$("#adbar-iframe-container").modal({overlayClose:true, containerCss:{height:'80%'}, onShow: function () {
				$("#adbar-iframe-container").hide();
				$("#adbar-iframe-container").fadeIn('fast');
				$("#adbar-iframe").attr('src', link);
				$("#adbar-iframe").ready(function () {
					$("#adbar-iframe").fadeIn('fast');
				});
			}});
			return false;
		});
	}
});

$(document).ready(function() {
	setTimeout(function () {
		// Show and slide up
		$("#adbar").show();
		$("#adbar").animate({
			'bottom': '+=81px'
		}, 850);
	}, 500);
});
