/** CHANGE SETTINGS HERE **/

var banner_dir = 'http://www.bdc-canada.com/banners/'; 	// Directory of images. If some are elsewhere, simply remove "banner_dir + ".
var text = '<a target="_blank" href="http://www.bdc-canada.com/sbw/index.html">New Seminars in Toronto - Learn About Small Business</a>';
			// Text to display at top of page. Set to false for none
var text_bg = banner_dir + 'text_bg.jpg';	// Background for text at top of page
var text_bg_height = 35;	// Height in pixels
var padding_left = 8; // Pixels to show between the edge of the content and the flag
var banner_width = 150;	// Set to the width of the widest flag PLUS padding_left.
var banners = {

	// FIRST FLAG
	//'Seminars': {	// This label will be used for alt text on the image.
	//	image: banner_dir + 'frontbanner-blue',	// What image to use (WITHOUT EXTENSION)
	//	lnk: 'http://www.bdc-canada.com/sbw/Offers.html', // Where the bannery should link to
	//	style: 'clear:both; float:right;'},	// 'float' value chooses which side of page to dislpay the banner on.
	// END FIRST FLAG

	// SECOND FLAG
	'Small Business': {
		image: banner_dir + 'frontbanner-red',
		lnk: 'http://www.bdc-canada.com/sbw/index.html',
		style: 'clear:both; float:right;' }
	// END SECOND FLAG

	// Add more here as necessary
};

/** DO NOT EDIT BELOW THIS LINE **/

var stylesheet = '#banner_text { background:url(\''+text_bg+'\') repeat-x scroll 0 0 #FFFFFF; text-align: center; font-family:\'Myriad Pro\',\'Gill Sans\',\'Gill Sans MT\',Calibri,sans-serif; font-weight:bold; font-size: 20px; color: white;height:35px;line-height:32px; }';
stylesheet += '#banner_text a, #banner_text a:visited, #banner_text a:hover, #banner_text a:focus { color:white; text-decoration:none; }';

// Sets "ie" to the ie version number, or undef if < 4.
//http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/
var ie = (function(){ 
     var undef,
        v = 3,
        div = document.createElement('div'),
        all = div.getElementsByTagName('i');
     while (
        div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
        all[0]
    );
     return v > 4 ? v : undef;
}());

// Positions the banner wrapper as desired, just to the right of the content
// TODO: Handle positionning on left
var setBannerPosition = function() {
	var container = $('#container');
	var offset = container.offset();
	var left_pos = (container.width() + offset.left + padding_left ) + 'px';
	var top_pos = text_bg
		? (offset.top-text_bg_height) + 'px'
		: offset.top + 'px';
	// Position
	$('#banner_wrapper').css({ 'float': 'none', 'position':'absolute', 'top':top_pos, 'left':left_pos });
	// Enforce an ie-compatable min-width for the text element
	if($(window).width() < container.width()) {
		$('#banner_text').css('width', (container.width()+padding_left*2) + 'px');
	} else {
		$('#banner_text').css('width', 'auto');
	}
};

// Adds all banners
var injectBanners = function() {
	if(document.getElementById('banner_wrapper')) return false;
	
	// Add styling rules
	$('head').append('<style type="text/css">'+stylesheet+'</style>');
	
	var wrapper = $('<div id="banner_wrapper" style="float:right;width:'+banner_width+'px;"></div>');
		// We'll manually position this later, but just in case, float it
	wrapper.css({'float': 'right', 'width': banner_width + 'px'	});
		// Add top-image to continue text background in case user scrolls right
	if(text_bg) {
		wrapper.css({'padding-top':text_bg_height, 'position': 'relative', 'top': '-'+text_bg_height+'px', 		'background-image': 'url('+text_bg+')', 'background-position': '0px 0px', 'background-repeat': 'repeat-x' });
	}
	for(banner in banners) {
		var alt = banner;
		var img = banners[banner].image;
		var lnk = banners[banner].lnk;
		var sty = banners[banner].style;
		wrapper.append("<a target='_BLANK' href='"+lnk+"'><img style='"+sty+"' src='"+img+(ie===6?'.gif':'.png')+"' alt='"+alt+"' /></a>");	
	}
	$('#container').before(wrapper);
	$('#container_header').after('<div id="banner_text">'+text+'</div>');
	
	// Add background images to body in case user scrolls right
	var dbody = $(document.body);
	var cheader = $('#container_header');
/*	dbody.css('background-image', 		cheader.css('background-image'));
	dbody.css('background-position', 	cheader.css('background-position'));
	dbody.css('background-repeat', 		cheader.css('background-repeat'));
*/	
	// Set position now and on every browser resize
	setBannerPosition();
	$(window).resize(setBannerPosition);
	// IE is being finicky (of course), so we make tripply sure positionning is done upon load
	$(document).load(setBannerPosition);
	setTimeout("setBannerPosition()", 500);
};

$(document).ready(function(){injectBanners();});

