(function($){

	//This function is used to put a unique number at the end of each ajax call to prevent ie from caching it.
	var nocache = function(url) {
		var rand = Math.floor(Math.random()*8999999999)+1000000000;
		url = url + (url.indexOf("?") == -1?"?nocache=":"&nocache=") + rand;
		return url;
	};

	var initSiteLayout = function() {
		
		//	disable caching of AJAX responses
		$.ajaxSetup ({
			cache: false
		});

		//	sets links with the rel of "blank" to open in a new window
		$('a[rel$="blank"]').attr('target', '_blank'); 
		
		//	confirm the submit button		
		$('input[type="submit"]').click(function() {
			if(this.title != '') {
				if(confirm(this.title)) { 
					if(!$(this).hasClass('no_wait')) {	$(this).attr("value", "Please wait ..."); } 
					this.submit; return true; this.disabled=true; 
				} else { return false; }
			} else {
				if(!$(this).hasClass('no_wait')) {	$(this).attr("value", "Please wait ..."); } 
				this.submit; return true; this.disabled=true;
			}
		});
		
		//	activating fancyzoom
		if( $('a[rel*=facebox]').length > 0 ) {
			 $('a[rel*=facebox]').facebox({ opacity : 0.8, overlay: true, loadingImage: '/static/images/site/facebox/loading.gif', closeImage: '/static/images/site/facebox/closelabel.gif'}) 
		}

		//	jobs accordion
		if( $('.jobs').length > 0 ) {
			$('.jobs').accordion();
		}

		//	contact form
		if( $('.formcontact').length > 0 ) {
			$('a.send').contactform();
		}
		
		//	printing articles
		$('.printing').bind('click', function(){
			window.print();
			return false;
		});
		
		//	flasher
		if( $('#flasher').length > 0 ) {
			$('#flasher').flash({   
				swf: '/static/flash/site/flasher.swf',
				height: 235,
				width: 665
			});
		};
		
		//	articles changing font size
		if( $('.text-size').length > 0 ) {
			$('.text-size').changeTextSize('.text-descr');
		}

		//	show me more text
		if( $('span.show_me_more').length > 0 ) {
			$('span.show_me_more').click(function(e) {
				$(this).parent().animate({ opacity: 0 }, { duration:300 }).hide('fast');
				$(this).parent().prev().show('fast').animate({ opacity: 1 }, { duration:300 });
			})
			$('span.show_me_less').click(function(e) {
				$(this).parent().next().show('fast').animate({ opacity: 1 }, { duration:300 });
				$(this).parent().animate({ opacity: 0 }, { duration:300 }).hide('fast');
			})
		}

		//	start the infotrafic live
		if( $('.infotrafic').length > 0 ) {
			var options = {
					url: '/index/?live=infotrafic',
					timer: 30,
					cookie_name: 'infotrafic',
					cookie_expires: 10,
					animate: true
				};
			$('.infotrafic').livedata(options);
		}
		
	};
	Site.register(initSiteLayout, 'init');
})(jQuery)
