$(document).ready
(
	function()
	{
		$('.container_adv').css('display', 'none');
		$('#block_code').css('display', 'none');
		$('#adv_text').css('display', 'block');
		$('input[name="get_code"]').click(function(){
		$('#block_code').css('display', 'block');
		
		var script_name = 'PL_ads';// + script_number;
		var script_code = '\<script type="text/javascript"\>\n' +
'var '+ script_name +'		= new Object();\n' +
script_name +'.block		= new Object();\n' +
script_name +'.fontsize		= new Object();\n' +
script_name +'.colors		= new Object();\n' +
script_name +'.pad_number	= '+$(this).parent().find('select[name="site_id"]').attr('value')+';\n';

if ($(this).parent().find('select[name="baner_type"]').size() > 0)
{
	script_code = script_code + script_name +'.banner_type	= "'+$(this).parent().find('select[name="baner_type"]').attr('value')+'";\n';
};
if ($(this).parent().find('input[name="ads_count"]').size() > 0)
{
	script_code = script_code + script_name +'.count_ad		= '+$(this).parent().find('input[name="ads_count"]').attr('value')+';\n';
};
if ($(this).parent().find('input[name="ads_separator"]').size() > 0)
{
	script_code = script_code + script_name +'.separator		= "'+encodeURIComponent($(this).parent().find('input[name="ads_separator"]').attr('value'))+'";\n';
};
if ($(this).parent().find('select[name="block_format"]').size() > 0)
{
	script_code = script_code + script_name +'.block.type	= "'+$(this).parent().find('select[name="block_format"]').attr('value')+'";\n';
};
if ($(this).parent().find('select[name="text_position"]').size() > 0)
{
	script_code = script_code + script_name +'.block.textpos	= "'+$(this).parent().find('select[name="text_position"]').attr('value')+'";\n';
};
if ($(this).parent().find('input[name="block_width"]').size() > 0)
{
	script_code = script_code + script_name +'.block.width	= '+$(this).parent().find('input[name="block_width"]').attr('value')+';\n';
};
if ($(this).parent().find('input[name="fSize_text"]').size() > 0)
{
	script_code = script_code + script_name +'.fontsize.ads	= "'+$(this).parent().find('input[name="fSize_text"]').attr('value')+'pt";\n';
};
if ($(this).parent().find('input[name="fSize_link"]').size() > 0)
{
	script_code = script_code + script_name +'.fontsize.link	= "'+$(this).parent().find('input[name="fSize_link"]').attr('value')+'pt";\n';
};
if ($(this).parent().find('input[name="fSize_domain"]').size() > 0)
{
	script_code = script_code + script_name +'.fontsize.dom	= "'+$(this).parent().find('input[name="fSize_domain"]').attr('value')+'pt";\n';
};
if ($(this).parent().find('input[name="fSize_stuff"]').size() > 0)
{
	script_code = script_code + script_name +'.fontsize.stuff	= "'+$(this).parent().find('input[name="fSize_stuff"]').attr('value')+'pt";\n';
};
/******************************************************/
if ($(this).parent().find('input[name="fColor_text"]').size() > 0)
{
	script_code = script_code + script_name +'.colors.ads	= "'+$(this).parent().find('input[name="fColor_text"]').attr('value')+'";\n';
};
if ($(this).parent().find('input[name="fColor_link"]').size() > 0)
{
	script_code = script_code + script_name +'.colors.link	= "'+$(this).parent().find('input[name="fColor_link"]').attr('value')+'";\n';
};
if ($(this).parent().find('input[name="fColor_domain"]').size() > 0)
{
	script_code = script_code + script_name +'.colors.dom	= "'+$(this).parent().find('input[name="fColor_domain"]').attr('value')+'";\n';
};
if ($(this).parent().find('input[name="fColor_stuff"]').size() > 0)
{
	script_code = script_code + script_name +'.colors.stuff	= "'+$(this).parent().find('input[name="fColor_stuff"]').attr('value')+'";\n';
};
if ($(this).parent().find('input[name="fColor_bg"]').size() > 0)
{
	script_code = script_code + script_name +'.colors.fon	= "'+$(this).parent().find('input[name="fColor_bg"]').attr('value')+'";\n';
};

script_code = script_code + script_name +'.adv_type	= "'+$(this).parent().parent().attr('id')+'";\n';

script_code = script_code + '\</script\>\n';

script_code = script_code + '\<script type="text/javascript" src="http://www.profi-link.org/public/link_block.js" \>\</script\>';


		
		$('#block_code').text(script_code);
		
	});	
	$('select[name="block_format"]').change(function(){
		if ($(this).attr('value') == 'vertical')
		{
			//if ($(this).parent().children('input[name="block_width"]').attr('value_')
			$(this).parent().children('input[name="block_width"]').attr('value', $(this).parent().children('input[name="block_width"]').attr('value_'));
		}
		if ($(this).attr('value') == 'horizontal')
		{
			$(this).parent().children('input[name="block_width"]').attr('value_', $(this).parent().children('input[name="block_width"]').attr('value'));
			$(this).parent().children('input[name="block_width"]').attr('value', '950');
		}
	});
	$('.buttons>div').each(function (index, element){
		var w = $(this).width()+60;
		$(this).width(w);
		$(this).css('text-align', 'center');
	});
	$('.buttons>div').click(function(){
		$('#block_code').css('display', 'none');
		switch($(this).attr('id'))
		{
			case 'btn_text':
				$('.container_adv').css('display', 'none');
				$('#adv_text').css('display', 'block');
			break;
			case 'btn_text_a':
				$('.container_adv').css('display', 'none');
				$('#adv_text_a').css('display', 'block');
			break;
			case 'btn_tizer':
				$('.container_adv').css('display', 'none');
				$('#adv_tizer').css('display', 'block');
			break;
			case 'btn_banner':
				$('.container_adv').css('display', 'none');
				$('#adv_banner').css('display', 'block');
			break;
			case 'btn_form':
				$('.container_adv').css('display', 'none');
				$('#adv_form').css('display', 'block');
			break;
			case 'btn_corner':
				$('.container_adv').css('display', 'none');
				$('#adv_corner').css('display', 'block');
			break;
		}
	});
		
		//$("#add_feedback").click(function(){$("#review_text").css('display', 'none'); $("#review_text1").css('display', 'block'); })
		$("ul.spy1").simpleSpy();
		$.tools.overlay.addEffect
		(
			"myEffect",
			function(position, done)
			{
				this.getOverlay().css(position).fadeIn(this.getConf().speed, done);
			},
			function(done)
			{
				this.getOverlay().fadeOut(this.getConf().closeSpeed, done);
			}
		);
		
		var trigLog = $("#trigLogin").overlay
		({
			mask:
			{
				color: '#333',
				loadSpeed: 200,
				opacity: 0.9
			},
			effect: 'myEffect',
			closeOnClick: true
		});
		
		
		var feedBack = $("#add_feed").overlay
		({
			mask:
			{
				color: '#333',
				loadSpeed: 200,
				opacity: 0.9
			},
		effect: 'myEffect',
		closeOnClick: true,
		height: 300,
		top: 1200
		});

		
		var trigReg = $("#trigRegister").overlay
		({
			mask:
			{
				color: '#444',
				loadSpeed: 200,
				opacity: 0.9
			},
			effect: 'myEffect',
			closeOnClick: true
		});
		
		$("#logindiv .cancel").click(function(e)
		{
			trigLog.eq(0).overlay().close();
		});
		
		$("#registerdiv .cancel").click(function(e)
		{
			trigReg.eq(0).overlay().close();
		});
/*	
		$(".newsticker-jcarousellite").jCarouselLite
		({  
        	vertical: true,  
	        visible: 2,  
    	    auto:1500,  
        	speed:1500  
		});
*/		
		$('#_ds').data('currentPosition', 'center');
		$('#_ds').data('link', '/home/advertiser');
		$('#web').data('currentPosition', 'left');
		$('#web').data('link', '/home/webmaster');
		$('#par').data('currentPosition', 'right');
		$('#par').data('link', '/home/partner');
		$('#_ds .infoContent').data('position', 'center');
		$('#_ds .infoContent').data('link', '/home/advertiser');
		$('#web .infoContent').data('position', 'left');
		$('#web .infoContent').data('link', '/home/webmaster');
		$('#par .infoContent').data('position', 'right');
		$('#par .infoContent').data('link', '/home/partner');
		$('#pic_menu img').hoverpulse();
		

		
/*
		$('.smallInfo h3').hover
		(
			function()
			{
				$(this).parent().parent().parent().parent().parent().parent().parent().children('.infoBlock').css('background-image', 'url(images/bg_big.png)');
			},
			function()
			{
				$(this).parent().parent().parent().parent().parent().parent().parent().children('.infoBlock').css('background-image', 'url(images/bg_small.png)');
			}
		);
*/
/*
		$('.infoContent').click
		(
			function()
			{
//				alert($(this).data('position'));
				if ($(this).data('position')=='center'){window.location='http://www.profi-link.org' + $(this).data('link'); return false};

				var n = $('#info *').queue("fx");
				if (n.length>'0'){return false};
				
				var centerDiv = null;
				if ($('#ads .infoContent').data('position') == 'center'){centerDiv = $('#ads')};
				if ($('#web .infoContent').data('position') == 'center'){centerDiv = $('#web')};
				if ($('#par .infoContent').data('position') == 'center'){centerDiv = $('#par')};
				
				if ($(this).data('position')=='left')
				{
					centerDiv.animate({left: '335px', top: '45px', width: '369px', height: '351px'}, 'slow', function()
					{
						centerDiv.children().css('backgroundImage', 'url(images/bg_small.png)');
						centerDiv.css('zIndex', '10');
						centerDiv.css('zIndex', '60');
						centerDiv.animate({left: '45px'}, 'slow', function()
						{
//							alert(centerDiv.data('position'));
						});
					});
					centerDiv.children().animate({width: '369px', height: '351px', fontSize: '10pt'}, 'slow'); // .infoBlock
					centerDiv.children().children().animate({width: '369px', height: '351px'}, 'slow'); // .border_top
					centerDiv.children().children().children().animate({width: '369px', height: '351px'}, 'slow'); // .border_left
					centerDiv.children().children().children().children().animate({width: '369px', height: '351px'}, 'slow'); // .border_right
					centerDiv.children().children().children().children().children().animate({width: '369px', height: '351px'}, 'slow'); // .border_bottom
					centerDiv.children().children().children().children().children().children().animate({width: '339px', height: '321px'}, 'slow'); // .infoContent
					centerDiv.find('.infoContent *').animate({width: '100%'}, 'slow');
					
					var sideDiv = $(this).parent().parent().parent().parent().parent().parent();
					sideDiv.animate({left: '0px', top: '0px', width: '461px', height: '438px'}, 'slow', function()
					{
						sideDiv.animate({left: '290px'}, 'slow', function()
						{
//							alert(sideDiv.data('position'));
						});
					});
					sideDiv.css('zIndex', '60');
					sideDiv.css('zIndex', '100');
					sideDiv.children().css('backgroundImage', 'url(images/bg_big.png)');
					sideDiv.children().animate({width: '461px', height: '438px', fontSize: '12pt'}, 'slow'); // .infoBlock
					sideDiv.children().children().animate({width: '461px', height: '438px'}, 'slow'); // .border_top
					sideDiv.children().children().children().animate({width: '461px', height: '438px'}, 'slow'); // .border_left
					sideDiv.children().children().children().children().animate({width: '461px', height: '438px'}, 'slow'); // .border_right
					sideDiv.children().children().children().children().children().animate({width: '461px', height: '438px'}, 'slow'); // .border_bottom
					sideDiv.children().children().children().children().children().children().animate({width: '431px', height: '408px'}, 'slow'); // .infoContent
					sideDiv.find('.infoContent *').animate({width: '100%'}, 'slow');
					
					centerDiv.find('.infoContent').data('position', 'left');
					sideDiv.find('.infoContent').data('position', 'center');					
				};
				
				if ($(this).data('position')=='right')
				{
					centerDiv.animate({left: '335px', right: '704px', top: '45px', width: '369px', height: '351px'}, 'slow', function()
					{
						centerDiv.children().css('backgroundImage', 'url(images/bg_small.png)');
						centerDiv.css('zIndex', '10');
						centerDiv.css('zIndex', '60');
						centerDiv.animate({left: '626px', right: '45px'}, 'slow', function()
						{
//							alert(centerDiv.data('position'));
						});
					});
					centerDiv.children().animate({width: '369px', height: '351px', fontSize: '10pt'}, 'slow'); // .infoBlock
					centerDiv.children().children().animate({width: '369px', height: '351px'}, 'slow'); // .border_top
					centerDiv.children().children().children().animate({width: '369px', height: '351px'}, 'slow'); // .border_left
					centerDiv.children().children().children().children().animate({width: '369px', height: '351px'}, 'slow'); // .border_right
					centerDiv.children().children().children().children().children().animate({width: '369px', height: '351px'}, 'slow'); // .border_bottom
					centerDiv.children().children().children().children().children().children().animate({width: '339px', height: '321px'}, 'slow'); // .infoContent
					centerDiv.find('.infoContent *').animate({width: '100%'}, 'slow');
					
					var sideDiv = $(this).parent().parent().parent().parent().parent().parent();
					sideDiv.animate({left: '599px', right: '0px', top: '0px', width: '461px', height: '438px'}, 'slow', function()
					{
						sideDiv.animate({left: '290px'}, 'slow', function()
						{
//							alert(sideDiv.data('position'));
						});
					});
					sideDiv.css('zIndex', '60');
					sideDiv.css('zIndex', '100');
					sideDiv.children().css('backgroundImage', 'url(images/bg_big.png)');
					sideDiv.children().animate({width: '461px', height: '438px', fontSize: '12pt'}, 'slow'); // .infoBlock
					sideDiv.children().children().animate({width: '461px', height: '438px'}, 'slow'); // .border_top
					sideDiv.children().children().children().animate({width: '461px', height: '438px'}, 'slow'); // .border_left
					sideDiv.children().children().children().children().animate({width: '461px', height: '438px'}, 'slow'); // .border_right
					sideDiv.children().children().children().children().children().animate({width: '461px', height: '438px'}, 'slow'); // .border_bottom
					sideDiv.children().children().children().children().children().children().animate({width: '431px', height: '408px'}, 'slow'); // .infoContent
					sideDiv.find('.infoContent *').animate({width: '100%'}, 'slow');
					
					centerDiv.find('.infoContent').data('position', 'right');
					sideDiv.find('.infoContent').data('position', 'center');					
				};
			}
		);
*/
		
		$('#_ds, #web, #par').click
		(
		 	function()
			{
				// определяем бокс по которму кликнули мышом
				var currentDiv = $(this);				
				// если кликнут центральный бокс - выходим
				if (currentDiv.data('currentPosition')=='center')
				{
					
					window.location='http://www.profi-link.org' + currentDiv.data('link');
					return false;
				}
				
				// узнаем куда смещать центральный бокс
				var pos_l = null;
				var pos_r = null;
				if (currentDiv.data('currentPosition')=='left')
				{
					pos_l = '0px';
					pos_r = 'auto';
				}
				if (currentDiv.data('currentPosition')=='right')
				{
					pos_l = '581px';
					pos_r = 'auto';
				}
				
				// определяем центральный бокс
				var centerDiv = null;
				if ($('#_ds').data('currentPosition')=='center'){centerDiv = $('#_ds.bigInfo')};
				if ($('#web').data('currentPosition')=='center'){centerDiv = $('#web.bigInfo')};
				if ($('#par').data('currentPosition')=='center'){centerDiv = $('#par.bigInfo')};
				
				// анимируем центральный бокс
				centerDiv.fadeOut('slow', function()
				{
					$(this).removeClass('bigInfo').addClass('smallInfo').css('left', pos_l).css('right', pos_r).css('top', '45px').css('zIndex', '50');
				}).fadeIn('slow', function()
				{
					centerDiv.data('currentPosition', currentDiv.data('currentPosition'));
				});
				
				// анимируем кликнутый бокс
				currentDiv.fadeOut('slow', function()
				{
					$(this).removeClass('smallInfo').addClass('bigInfo').css('left', '245px').css('right', '706px').css('top', '0px').css('zIndex', '100');
				}).fadeIn('slow', function()
				{
					currentDiv.data('currentPosition', 'center');
				});
			}
		)
	}
);
