$(document).ready(function() {
    // Загрузка главной страницы
    $('#main-content').load('home-frame.html', function() {
	$("img[usemap=#top-menu-map]").attr('src', 'images/menu-home.png');

	$("#accordion-icons").flash({
	    src    : 'icons.swf',
	    width  : 252,
	    height : 77,
	    wmode  : 'transparent'
	});

	$("#accordion").accordion({autoHeight: true});

	$('#header .content .logo').flash({
	    src    : 'logo.swf',
	    width  : 133,
	    height : 34
	});
	$('#header .content .item').flash({
	    src    : 'preview.swf',
	    width  : 123,
	    height : 27
	});
	$('#main-flash').flash({
	    src    : 'news.swf',
	    width  : 936,
	    height : 212,
	    wmode  : 'transparent'
	});
	$('#body .bottom').flash({
	    src    : 'preview1.swf',
	    width  : 252,
	    height : 77,
	    wmode  : 'transparent'
	});
	$('#search-form').flash({
	    src    : 'Subscribe/subscribe.swf',
	    width  : 240,
	    height : 50,
	    wmode  : 'transparent'
	});
	menu_init('#top-menu-map area, #bottom-menu a, #reviews-title, #dates-title');
    });
});

function menu_init(selector) {
    // Инициализация меню
    if (!selector) return;
    $(selector).click(function() {
	switch ($(this).attr('href')) {
	    case 'index.html':
		$('#main-content').load('home-frame.html', function() {
		    $("img[usemap=#top-menu-map]").attr('src', 'images/menu-home.png');
		    $("#accordion-icons").flash({
			src    : 'icons.swf',
			width  : 252,
			height : 77,
			wmode  : 'transparent'
		    });

		    try{$("#accordion").accordion({autoHeight: false});} catch(e) {/**/}
		    menu_init('#reviews-title, #dates-title');
		});
	    break;
	    case 'dates.html':
		$('#main-content').load('dates-frame.html', function() {
		    $("img[usemap=#top-menu-map]").attr('src', 'images/menu-dates.png');
		    $('#accordion').addClass('flexcroll').css({
			    width: '890px',
			    height: '368px',
			    overflow: 'auto', // IE overflow fix, position must be relative or absolute
			    position: 'relative'
		    });
		    $("#accordion").accordion({autoHeight: false});
		    $('#accordion').jScrollPane({showArrows:true, scrollbarWidth:14, dragMaxHeight:32});
		    menu_init();
		});
	    break;
	    case 'about.html':
		$('#main-content').load('about-frame.html', function() {
		    $("img[usemap=#top-menu-map]").attr('src', 'images/menu-about.png');
		    $('#about-text').jScrollPane({showArrows:true, scrollbarWidth:14, dragMaxHeight:32});
		    menu_init();
		});
	    break;
	    case 'releases.html':
		$('#main-content').load('releases-frame.html', function() {
		    $("img[usemap=#top-menu-map]").attr('src', 'images/menu-releases.png');
		    $('#albums').jScrollPane({showArrows:true, scrollbarWidth:14, dragMaxHeight:32});
		    $('.jScrollPaneContainer').css({'width':'306px'});
		    menu_init();
		});
	    break;
	    case 'mixtabes.html':
		$('#main-content').load('mixtabes-frame.html', function() {
		    $("img[usemap=#top-menu-map]").attr('src', 'images/menu-mixtabes.png');
		    $('#albums').jScrollPane({showArrows:true, scrollbarWidth:14, dragMaxHeight:32});
		    $('.jScrollPaneContainer').css({'width':'306px'});
		    menu_init();
		});
	    break;
	    case 'kontakt.html':
		$('#main-content').load('kontakt-frame.html', function() {
		    $("img[usemap=#top-menu-map]").attr('src', 'images/menu-kontakt.png');
		    $('.date-edit').datepicker();
		    $('form input[type=submit]').click(function() {
			 mail_submit(document.forms[0]);
			 return false;
		    });
		    menu_init();
		});
	    break;
	    case 'gallery.html':
		$('#main-content').load('gallery/gallery-frame.html', function() {
		    $("img[usemap=#top-menu-map]").attr('src', 'images/menu-gallery.png');
		});
		menu_init();
	    break;
	    case 'feedbacks.html':
		$('#main-content').load('GB/feedbacks-frame.html', function() {
		    $("img[usemap=#top-menu-map]").attr('src', 'images/menu-feedback.png');
		});
		menu_init();
	    break;
	    default: return true;
	}
	return false;
    });
}


function show_preview(id) {
    $('#releases-preview .album-preview').css('display', 'none');
    $('#' + id).css('display', 'block');
    return false;
}

function mail_submit(mail_form) {
    if (!mail_validate(mail_form)) return false;
    var data = {};
    $('input', mail_form).each(function() {
	if ($(this).val() && $(this).attr('name')) {
	    data[$(this).attr('name')] = $(this).val();
	}
    });
    $.post('common.php', data, function(answer) {
	if (parseInt(answer) == 1) {
	    alert('Your mail sent succesfull.');
	} else alert('Your mail not sent')
    });
}
function mail_validate(mail_form) {
    if (mail_form) {
	$('input', mail_form).each(function() {
	    if (!$(this).val()) {
		alert('Please fill all form fields');
		return false;
	    }
	});
	return true;
    }
    return false;
}
