//Preload images
pic1 = new Image();
pic1.src="/templates/img/tooltip.png";

$(document).ready(function(){		   
	$('.icon').bind("mouseenter", function(){	
		var that = $(this);
		var tid = that.attr('id');
		var tid = tid.substr(6,tid.length-5);
		
		var title = $('#idesc_id_'+tid).html();
		var offset = that.offset();
		var popup = $('#popup');
		
		that.find('.ico').hide();
		that.find('.ico_on').show();
		
		//alert(tid);
		
		if(title){
			popup.find('.popup_inner').html(title);
			popup.css('left', offset.left);
			popup.css('top', offset.top);
			
			if ($.browser.msie){
				popup.show();
			}else{
				popup.show();
			};
		};
	});
	
	$('.icon').bind("mouseleave", function(){
	 	var that = $(this);
		
		if ($.browser.msie){
			$('#popup').css('left', '-5000px');
		}else{
			$('#popup').hide();
		};
		
		that.find('.ico').show();
		that.find('.ico_on').hide();
	});
	
	$('.pi').bind("mouseenter", function(){	
		var that = $(this);
		var title = that.find('.item_description').html();
		var offset = that.offset();
		var popup_inv = $('#popup_inv');
		
		$(this).find('.pi_i').hide();
		$(this).find('.pi_a').show();
		
		if(title){
			popup_inv.find('.popup_inner').html(title);
			popup_inv.css('left', offset.left);
			popup_inv.css('top', offset.top);
			
			if ($.browser.msie){
				popup_inv.show();
			}else{
				popup_inv.show();
			};
		};
	});
	
	$('.pi').bind("mouseleave", function(){
	 	var that = $(this);
		
		$(this).find('.pi_i').show();
		$(this).find('.pi_a').hide();
		
		if ($.browser.msie){
			$('#popup_inv').css('left', '-5000px');
		}else{
			$('#popup_inv').hide();
		};
	});

    $('#textversion_link').mouseover(function(){
        $('#articles_list').css({top: $(document).height() - $('#articles_list').height() - 60}).fadeIn().bind('mouseleave', function(){
            $('#articles_list').fadeOut().unbind('mouseleave');
        });
    });
});

function open_addicon(){
	document.getElementById('opener_iconadd').style.display = 'none';
	document.getElementById('closer_iconadd').style.display = 'block';
	$('#my_collection').slideUp();
	$('#add_icon_block').slideDown();
	$('.ad_icon').hide();
}

function close_addicon(){
	document.getElementById('opener_iconadd').style.display = 'block';
	document.getElementById('closer_iconadd').style.display = 'none';
	$('#my_collection').slideDown();
	$('#add_icon_block').slideUp();
	setTimeout("$('.ad_icon').show()", 300);
}

$(document).ready(function(){						   
	$('.mainpagelink').hover(function(){
		$(this).children().hide();
		$(this).children().next().show();
	},function(){
		$(this).children().show();
		$(this).children().next().hide();
	});
						   
	if($.browser.name == 'firefox'){
		$('.st_ff').show();
	};
	if($.browser.name == 'msie'){
		$('.st_ie').show();
	};
	if($.browser.name == 'chrome'){
		$('.st_ch').show();
	};
	if($.browser.name == 'opera'){
		$('.st_op').show();
	};
	if($.browser.name == 'safari'){
		$('.st_sa').show();
	};

	//Bubbles
	setTimeout("$('.register_bubble').slideDown('slow')", 800);
	setTimeout("$('.register_bubble').slideUp('slow')", 10000);
	
	$('.menu_1').hover(function(){
		$('.register_bubble').slideDown('fast');
	},function(){
		setTimeout("$('.register_bubble').slideUp('slow')", 4000);
	});
	
	$('.logo').hover(function(){
		$('.main_bubble').slideDown('fast');
	},function(){
		setTimeout("$('.main_bubble').slideUp('slow')", 3000);
	});
	
	$('.home_btn').hover(function(){
		$('.home_bubble').slideDown('fast');
	},function(){
		setTimeout("$('.home_bubble').slideUp('slow')", 3000);
	});
});

function delete_icon(id, name){
	if(confirm('Вы действительно хотите удалить иконку «' + name + '»?')){
		document.location.href="?action=delete_icon&id="+id;
	}
}


function delete_loaded_icon(id, name){
	if(confirm('Вы действительно хотите удалить иконку «' + name + '»?')){
		document.location.href="?action=delete_loaded_icon&id="+id;
	}
}

function addTexture(){
	$('#my_textures').slideDown();
	$('#default_textures').slideUp();
}

function closeAdd(){
	$('#my_textures').slideUp();
	$('#default_textures').slideDown();
}

function closeAdd2(){
	$('#add_selects').show();
	$('#addPhoto, #addTexture').hide();
}

function tAdd(){
	$('#add_selects').hide();
	$('#addTexture').show();
}

function pAdd(){
	$('#add_selects').hide();
	$('#addPhoto').show();
}

function delPh(){
	if(confirm('Удалить Фотографию?')){
		document.location.href='/myiknop/settings/?action=delPh';
	};
}

function delTe(){
	if(confirm('Удалить текстуру?')){
		document.location.href='/myiknop/settings/?action=delTe';
	};
};

function goUrl(id, type){
	if(type == 1){
		window.open('/gouserurl/'+id, '_blank');
	}else{
		window.open('/gourl/'+id, '_blank');
	};
};
