$(document).ready(function(){

	// TEMPLATE LEFT TABS NEXT/PREV
	$('.templatedet_left_tabs').cycle({speed: 1,
		                           timeout: 0,
			                   prev: '.templatedet_left_nextprev .ttab_prev',
			                   next: '.templatedet_left_nextprev .ttab_next'});


	// TEMPLATE LEFT TABS CLICK
	$('.templatedet_left_tabs .tab').click(function(){
		$('.templatedet_left_tabs .tab').removeClass('selected');
		$(this).addClass('selected');

		$('.templatedet_left_images .image').removeClass('selected');
		$('.templatedet_left_images #c'+$(this).attr('id')).addClass('selected');

		// TEMPLATE DETAILS - EQUAL LEFT-RIGHT COLUMNS
		var h1 = $('.templatedet_right_infos').height();
		var h2 = $('.templatedet_left_images #c'+$(this).attr('id')+' .image').height()-15+'px';
		if(h2 > h1) $('.templatedet_right_infos').css('height', h2);
		else $('.templatedet_left_images #c'+$(this).attr('id')+' .image').height(h1);
	});


	// ROLLUP/ROLLDOWN LEFT SEARCH BUTTONS
	$('.frolldown a').click(function(){
		$('#leftSearchInputs').animate({height: 202}, 100);
		$('#leftSearchButtons .frolldown').css('display', 'none');
		$('#leftSearchButtons .frollup').css('display', 'block');

		return false;
	});

	$('.frollup a').click(function(){
		$('#leftSearchInputs').animate({height: 57}, 100);
		$('#leftSearchButtons .frolldown').css('display', 'block');
		$('#leftSearchButtons .frollup').css('display', 'none');

		return false;
	});

	// TEMPLATE FLASH PREVIEW
	$('.flash_preview').click(function(){
		tb_show($(this).text(),$(this).attr('link'),'');

		return false;
	});

	// CLIPBOARD/CART TABS
	$('#leftClipboardCart .tab').click(function(){
		$('#leftClipboardCart .tab').removeClass('selected');
		$(this).addClass('selected');

		$('#leftClipboardCart .content').removeClass('selected');
		$('#leftClipboardCart #c'+$(this).attr('id')).addClass('selected');

		return false;
	});


	// ROLLUP/ROLLDOWN CART HOSTING PARAMS
	$('.hprolldown a').click(function(){
		$(this).parent().parent().prev('.hosting_params').animate({height: 208}, 100);
		$(this).parent('.hprolldown').css('display', 'none');
		$(this).parent().parent().find('.hprollup').css('display', 'block');

		return false;
	});

	$('.hprollup a').click(function(){
		$(this).parent().parent().prev('.hosting_params').animate({height: 79}, 100);
		$(this).parent('.hprollup').css('display', 'none');
		$(this).parent().parent().find('.hprolldown').css('display', 'block');

		return false;
	});

	// ROLLUP/ROLLDOWN PRICING VERSIONS PARAMS
	$('.vpprolldown a').click(function(){
		var items = 0;
		$(this).parent().parent().parent().find('.left').each(function(){
			items++;
		});
		var rolldownheight = 63 + 28 + 16*(items-4);

		$(this).parent().parent().prev('.params').animate({height: rolldownheight}, 100);
		$(this).parent('.vpprolldown').css('display', 'none');
		$(this).parent().parent().find('.vpprollup').css('display', 'block');

		return false;
	});

	$('.vpprollup a').click(function(){
		$(this).parent().parent().prev('.params').animate({height: 63}, 100);
		$(this).parent('.vpprollup').css('display', 'none');
		$(this).parent().parent().find('.vpprolldown').css('display', 'block');

		return false;
	});

	// ROLLUP/ROLLDOWN PRICING HOSTING PARAMS
	$('.hpprolldown a').click(function(){
		$(this).parent().parent().prev('.params').animate({height: 208}, 100);
		$(this).parent('.hpprolldown').css('display', 'none');
		$(this).parent().parent().find('.hpprollup').css('display', 'block');

		return false;
	});

	$('.hpprollup a').click(function(){
		$(this).parent().parent().prev('.params').animate({height: 79}, 100);
		$(this).parent('.hpprollup').css('display', 'none');
		$(this).parent().parent().find('.hpprolldown').css('display', 'block');

		return false;
	});

	// ADDITIONAL MODULES IN PRICING FORM
	$('.modadd_checkbox').click(function(){
		$('form input[name=m_dod]').attr('value', '');

		$('.modadd_checkbox').each(function(){
			if($(this).attr('checked'))
			{
				$('form input[name=m_dod]').attr('value', $('form input[name=m_dod]').attr('value')+','+$(this).val());
			}
		});
	});

	// SERVICES IN PRICING FORM
	$('.services_checkbox').click(function(){
		$('form input[name=uslugi]').attr('value', '');

		$('.services_checkbox').each(function(){
			if($(this).attr('checked'))
			{
				$('form input[name=uslugi]').attr('value', $('form input[name=uslugi]').attr('value')+','+$(this).val());
			}
		});
	});

	// NO-HOSTING ACTION IN PRICING FORM
	$('.pricing_paytypes_item input[type=radio]').click(function(){
		if($(this).attr('class') == 'first')
		{
			$('.pricing_hosting_item.first input[type=radio]').removeAttr('disabled');
			$('.pricing_hosting_item.first .nohosting_1').css('display', 'block');
			$('.pricing_hosting_item.first .nohosting_2').css('display', 'none');
		}
		else
		{
			$('.pricing_hosting_item.first input[type=radio]').attr('disabled', 'disabled');
			$('.pricing_hosting_item.first .nohosting_1').css('display', 'none');
			$('.pricing_hosting_item.first .nohosting_2').css('display', 'block');
			if($('.pricing_hosting_item.first input[type=radio]').attr('checked'))
			{
				$('.pricing_hosting_item.second input[type=radio]').attr('checked', 'checked');
			}
		}
	});

	if($('.pricing_hosting_item.first input[type=radio]').attr('disabled'))
	{
		$('.pricing_hosting_item.first .nohosting_1').css('display', 'none');
		$('.pricing_hosting_item.first .nohosting_2').css('display', 'block');
	}

	// PP PANEL TABS
	$('.panel_pp_tabs .tab').click(function(){
		$('.panel_pp_tabs .tab').removeClass('selected');
		$(this).addClass('selected');

		$('.panel_pp_tabs_contents .content').removeClass('selected');
		$('.panel_pp_tabs_contents #c'+$(this).attr('id')).addClass('selected');
	});
});


$(window).load(function(){

	$('.templatedet_right_infos').css('height', $('.templatedet_right_infos').height()+97);

	var h1 = $('.templatedet_left_images').height();
	var h2 = $('.templatedet_right_infos').height();
	if(h2+21 > h1) $('.templatedet_left_images').css('height', h2+21);
	else $('.templatedet_right_infos').css('height', h1-21);

	$('.templatedet_right_b').css('display', 'block');
});
