// jQuery Functions 4 chel.pro
// на всех страницах
$(document).ready(function() {
	$('#navHomeButton')
		.attr('title', 'Перейти на главную страницу')
		.attr('style', 'cursor:hand;cursor:pointer;')
		.bind('click', function(){
			$('#content').html('<div class="loading"><img src="/wp-content/themes/chel/images/loading.gif" alt="loading"><br/>Страница загружается</div>');
			$('#pageLayout').css('background-image', 'url(/wp-content/themes/chel/images/body_bg.jpg)');
			$('#contentWrapper').load('/ #content', function(){
				//$.getScript('/wp-content/plugins/flash-video-player/swfobject.js', function() {
				//	console.log('SWF Object doesn\'t Reloaded.');
				//});
				//s0.write("video0");
			});
			return false;
		});
	$('#navNewsButton')
		.attr('title', 'Новости')
		.attr('style', 'cursor:hand;cursor:pointer;')
		.bind('click', function(){
			$('#content').html('<div class="loading"><img src="/wp-content/themes/chel/images/loading.gif" alt="loading"><br/>Страница загружается</div>');
			$('#pageLayout').css('background-image', 'url(/wp-content/themes/chel/images/cbg_news.jpg)');
			$('#contentWrapper').load('/news/ #content', function(resp, stat, xhr){
				var response = String(resp).replace(/\r\n/g, '');
				//console.log('Page loaded');
				var contents = response.match(/<script type=\"text\/javascript\">\nvar(.|\s)*?\/script>/gi);
				for(i = 0; i < contents.length; i++){
					var scriptBody = contents[i].replace(/<script type=\"text\/javascript\">/).replace(/<\/script>/);
					jQuery.globalEval(scriptBody);
				}
			});
			return false;
		});
	$('#navBioButton')
		.attr('title', 'Биография')
		.attr('style', 'cursor:hand;cursor:pointer;')
		.bind('click', function(){
			$('#content').html('<div class="loading"><img src="/wp-content/themes/chel/images/loading.gif" alt="loading"><br/>Страница загружается</div>');
			$('#pageLayout').css('background-image', 'url(/wp-content/themes/chel/images/cbg_bio.jpg)');
			$('#contentWrapper').load('/bio/ #content');
			return false;
		});
	$('#navGalleryButton')
		.attr('title', 'Галерея')
		.attr('style', 'cursor:hand;cursor:pointer;')
		.bind('click', function(){
			$('#content').html('<div class="loading"><img src="/wp-content/themes/chel/images/loading.gif" alt="loading"><br/>Страница загружается</div>');
			$('#pageLayout').css('background-image', 'url(/wp-content/themes/chel/images/cbg_gallery.jpg)');
			$('#contentWrapper').load('/gallery/ #content', function(){
				$('a', '#content').each(function(){
					var link = $(this);
					link.bind('click', function() {
						$('#content').html('<div class="loading"><img src="/wp-content/themes/chel/images/loading.gif" alt="loading"><br/>Страница загружается</div>');
						$('#contentWrapper').load(this.href + ' #content', function(){
							$.getScript('/wp-content/plugins/nggallery/shutter/shutter-reloaded.js?ver=1.3.0', function() {
								console.log('First script load was performed.');
							});
							$.getScript('/wp-content/plugins/nggallery/js/ngg.js?ver=2.9.2', function() {
								console.log('Second script load was performed.');
							});
						});
						return false;
					});
				});
			});
			return false;
		});
	$('#navDownloadButton')
		.attr('title', 'Скачать')
		.attr('style', 'cursor:hand;cursor:pointer;')
		.bind('click', function(){
			$('#content').html('<div class="loading"><img src="/wp-content/themes/chel/images/loading.gif" alt="loading"><br/>Страница загружается</div>');
			$('#pageLayout').css('background-image', 'url(/wp-content/themes/chel/images/cbg_download.jpg)');
			$('#contentWrapper').load('/download/ #content');
			return false;
		});
	$('#navContactsButton')
		.attr('title', 'Контакты')
		.attr('style', 'cursor:hand;cursor:pointer;')
		.bind('click', function(){
			$('#content').html('<div class="loading"><img src="/wp-content/themes/chel/images/loading.gif" alt="loading"><br/>Страница загружается</div>');
			$('#pageLayout').css('background-image', 'url(/wp-content/themes/chel/images/cbg_contacts.jpg)');
			$('#contentWrapper').load('/contacts/ #content');
			return false;
		});
	$('#navPartnersButton')
		.attr('title', 'Партнеры')
		.attr('style', 'cursor:hand;cursor:pointer;')
		.bind('click', function(){
			$('#content').html('<div class="loading"><img src="/wp-content/themes/chel/images/loading.gif" alt="loading"><br/>Страница загружается</div>');
			$('#pageLayout').css('background-image', 'url(/wp-content/themes/chel/images/cbg_partners.jpg)');
			$('#contentWrapper').load('/partners/ #content');
			return false;
		});
});


