// aOverrides is called from aUI()
// This helps for things like Cufon that need to be setup again after an AJAX call
function aOverrides() {

}

var numImages = 7;  //number of pictures in main banner
var shost = 'http://www.everen.pl';  //site host

var system = {
		
	start : function() {
		// this.test();
		this.animateTopBanner();
		
		// alternatywa dla target="_blank"
		$('a[rel="blank"]').click(function() {
			window.open(this.href);
			return false;
		});
		
		// dodaj do ulubionych
		if (window.opera) {
			if ($("a.jqbookmark").attr("rel") != "") { // don't overwrite the
				// rel attrib if already
				// set
				$("a.jqbookmark").attr("rel", "sidebar");
			}
		}

		$("a.jqbookmark")
				.click(function(event) {
					event.preventDefault(); // prevent the anchor tag from
						// sending the user off to the link
						var url = 'http://everen.pl';
						var title = 'Everen';

						if (window.sidebar) { // Mozilla Firefox Bookmark
							window.sidebar.addPanel(title, url, "");
						} else if (window.external) { // IE Favorite
							window.external.AddFavorite(url, title);
						} else if (window.opera) { // Opera 7+
							return false; // do nothing - the rel="sidebar"
							// should do the trick
						} else { // for Safari, Konq etc - browsers who do
							// not support bookmarking scripts (that i
							// could find anyway)
							alert('Niestety twoja przeglądarka nie obsługuje automatycznego dodawania strony do ulubionych.');
						}

		});
		
		$('a.lightbox').lightBox();
	},
	test : function() {
		alert('Fire System.Test');
	},
	animateTopBanner : function() {
		var currImageNb = Math.ceil(Math.random()* numImages);
		this.randomChangeTopBannerBg(currImageNb);
		
		setInterval(function() {
			
			var actualBg = $('#top-main-banner').css("background-image");
			do {
				var randImageNb = Math.ceil(Math.random()* numImages);
			} while (randImageNb == currImageNb)
			currImageNb = randImageNb;
			
			$('#top-main-banner').BgImageTransition('/images/main_banner/mb' + currImageNb + '.jpg');
			
		}, 8000)
	},
	randomChangeTopBannerBg : function(forceImgNb) {
		
		var img2change;
		if (forceImgNb){
			img2change = 'url(' + shost + '/images/main_banner/mb' + forceImgNb + '.jpg)';
		}else{
			var actualBg = $('#top-main-banner').css("background-image");
			var actualBg2 = $('#top-main-banner2').css("background-image");
			do {
				img2change = 'url(' + shost + '/images/main_banner/mb' + Math.ceil(Math.random()* numImages) + '.jpg)';
			} while (img2change == actualBg || img2change == actualBg2)
		}
		if ($('#top-main-banner2').css('display') != 'none'){
			$('#top-main-banner').css("background-image", img2change);
		}
	}
}

$(document).ready(function() {
	system.start();
});
