$(window).resize(function() {
	ResizeTop10();
	$('div.index_block').redrawShadow();
});
function ResizeTop10() {
	if ($(document).width() > 1024) {
		$('td.banners_page').show();
	}
	$('#index_top').width($('td.top10_central').width());
}
var photo_rotate = 10000;
var fl_rotate = true;
$(document).ready(function () {
	ResizeTop10();
	$('div.index_block').dropShadow({left:1, top:1, blur:2 });
	
	
	$('div.photobank_preview img').each(function () {
		var src = $(this).parent().attr('src');
		src = src.replace("/preview/","/");
		var title = $(this).parent().attr('title');
		$(this).wrap('<a href="' + src + '" title=\'' + title + '\' class=thickbox></a>');
	});
	$('div.index_photo img, div.index_photo_current img, div.photobank_pic img').each(function () {
		var src = $(this).parent().attr('src');
		src = src.replace("/pic/","/");
		var title = $(this).parent().attr('title');
		$(this).wrap('<a href="' + src + '" title=\'' + title + '\' class=thickbox></a>');
	});
	
	tb_init('a.thickbox');
	window.setTimeout(RotatePhoto, photo_rotate);
	// mouseover in articles menu
	$('div.article_short').each(function () {
		$(this).bind('mouseover', function() {
			$(this).attr('class', 'article_short_hover');
		}).bind('mouseout', function() {
			$(this).attr('class', 'article_short');
		}).bind('click', function() {
			location.href = $(this).find('a').attr('href');
		});
	});
	
	// corners
	$('div.newsb2_img, div.block_article_in_category').corner("round 4px");

	// navigator
	$('.tab_label, .tab_label_current').each(function() {
		$(this).bind('click', function () {
			$('#nav_center').show();
			$('div.tab, div.tab_current').hide();
			$('#t' + $(this).attr('id')).fadeIn('fast');
			$('div.tab_label_current').attr('class', 'tab_label');
			$(this).attr('class', 'tab_label_current');
			$('#navigator_arrow').attr('src', '/i/arrow_up.png');
			google.maps.event.trigger(map_nav, 'resize');
		});
	});
	
	// text shadow for ie
	if ($.browser.msie) {
		$('legend, div.tab_label, div.tab_label_current, div.sitemap a, h1, div.top10_title, div.top10_link a').textShadow();
	}
	
	
});
function IEPatch() {
}
function IEPatch2() {
}
function SwitchNavigatorBody(el) {
	$('#nav_center').toggle();
	if (el.attr('src') == "/i/arrow_up.png") {
		el.attr('src', '/i/arrow_down.png');
	}
	else {
		el.attr('src', '/i/arrow_up.png');
	}
}

function TogglePhoto(el) {
	var ind = el.attr('class');
	$('#index_photos').find('div.index_photo, div.index_photo_current').hide();
	$('#' + ind).fadeIn('fast');
	
	$('.block_photos img').each(function () {
		var im = $(this);
		if (im.attr('src').indexOf("_current") > 0) {
			if (ind == im.attr('class')) {
				im.show();
			}
			else {
				im.hide();
			}
		}
		else {
			if (ind == im.attr('class')) {
				im.hide();
			}
			else {
				im.show();
			}
		}
	});
}

function ShowPhoto(el) {
	TogglePhoto(el);
	fl_rotate = false;
}
function ShowPhotoAuto(el) {
	TogglePhoto(el);
}
var last_photo = 0;
var count_photo = 7;
function ShowBanners() {
	//if ($('body').css('width')
}
function RotatePhoto() {
	if (fl_rotate == false) return;
	
	last_photo = last_photo + 1;
	if (count_photo-1 < last_photo) {
		last_photo = 0;
	}
	ShowPhotoAuto($('#phb' + last_photo));
	window.setTimeout(RotatePhoto, photo_rotate);
}

var current_position = 0;
function MoveLeft() {
	var length = $('div#index_top table tr').get(0).childNodes.length;
	if (current_position == 0) {
		current_position = length-3+1;
	}
	//$('#index_top').scrollTo( '-=150px', 800 );
	$('#index_top').scrollTo($('div#index_top table tr').get(0).childNodes[current_position-1], 800);
	current_position--;
}
function MoveRight() {
	var length = $('div#index_top table tr').get(0).childNodes.length;
	if (length-3 == current_position) {
		current_position = -1;
	}
	//$('#index_top').scrollTo( '+=150px', 800 )
	$('#index_top').scrollTo($('div#index_top table tr').get(0).childNodes[current_position+1], 800);
	current_position++;
}


/*
	var shadow = new google.maps.MarkerImage(
		"http://www.google.com/mapfiles/shadow50.png",
		new google.maps.Size(37, 34),
		new google.maps.Point(0,0),
		new google.maps.Point(10, 34)
	);*/
	function getIcon(s) {
		if (s) {
			return "/img/markers/" + s;		
		}
		else {
			return "/img/markers/marker.png";
		}
	}
	function getShadow(s) {
		if (s) {
			return null;		
		}
		else {
			return shadow;
		}
	}
	function ShowAllItems() {
		$('#sensations_list').find('table').each(function() { $(this).show(); } )
		$('#island_id')[0].value = 0;
	}
	function ShowIWandFilter (iw, m, id) {
		ShowIW(iw, m, id);
		$('#island_id')[0].value=id;
		FilterList(id);
	}
	function FilterList(id) {
		if (id > 0) {
			$('#sensations_list').find('table').each(function() { if($(this).attr("name") != "island_"+id) { $(this).hide(); } else { $(this).show(); } } )		
		}	
		else {
			$('#sensations_list').find('table').each(function() { $(this).show(); } )
		}
	}
	function ShowIWnav (iw, m, id) {
		if (iw == last_iw) { return; }
		if (last_iw) { last_iw.close(); }
		iw.open(map_nav, m);
		last_iw = iw;
	}
	function ShowIW (iw, m, id) {
		if (iw == last_iw) { return; }
		if (last_iw) { last_iw.close(); }
		iw.open(map, m);
		last_iw = iw;
	}
	function CloseIW (iw) {
		iw.close();
		last_iw = null;
	}

function SendFeedback() {
	HideMessage();
	if ($('#email').val() == "") {
		ShowMessage("Ââåäèòå e-mail");
		return false;
	}
	PostData("xt_feedback");
}
function ShowMessage(text) {
	$('#message').text(text);
	$('#message').fadeIn();
}
function HideMessage() {
	$('.hide_when_form_submit').hide();
	$('#message').hide();
}

function PostData(form_id) {
	$("#"+form_id).find('.ajax_process').show();
	$("#"+form_id).find('.submit').attr('disabled', 'true');
	var script_name = $("#"+form_id).attr('action') || form_id;
	//alert($("#" + form_id).serialize());
	$.post("/cgi-bin/" + script_name + ".cgi", $("#" + form_id).serialize(),
		function(data){
			ProcessData(form_id, data);
		}, "json");
}
function ProcessData(form_id, data) {
	//alert("field: " + data.error_field + "\nmessage: " + data.error_text + "\nredirect: " + data.redirect); 
	if (data.redirect && !data.redirect_timeout) {
		location.href = data.redirect;
	}
	if (data.error_text) {
		ShowMessage(data.error_text);
	}
	$("#"+form_id).find('.ajax_process').hide();
	$("#"+form_id).find('.submit').attr('disabled', 0);
}
	
function ShowLastArticles() {
	if ( $('#link_show_last').is(':visible') )
	{
		$('#link_show_last').hide();
		$('#last_articles_div').show();
	} else 
	{
		$('#link_show_last').show();
		$('#last_articles_div').hide();
	}
}
