$(document).ready( function() {
	$('#edit-search-theme-form-keys').each(function() {
		var $this = $(this);
		var t = $this.attr('value');		
		$(this).click(function() {
			if($this.attr('value') == t) {$this.attr('value','');}
		});
		$(this).blur(function() {
			if($this.attr('value') == '') {$this.attr('value',t);}
		});
	});
	
	/* check in sub menu ar too long
	// and if so - slide them
	*/
	level2_length = 0;
	$('#block-slicedmenu-1 .menu li').each(
		function() {
			level2_length += $(this).width();
		}	
	)
	if(level2_length>940) {
		$('#block-slicedmenu-1 .content').wrap('<div id = "levelslider1"></div>');
		$("#levelslider1").append("<div class = 'slider slideright'>></div>");
		$("#levelslider1").append("<div class = 'slider slideleft'><</div>");
		$('#block-slicedmenu-1 .slideright').click(
			function() {
				if($('#block-slicedmenu-1 .menu').css('left') != "-" + (level2_length - 930  + "px")) {
					$('#block-slicedmenu-1 .menu').animate({"left": "-=" + (level2_length - 920 ) + "px"}, "slow");
				}
			}
		)
		$('#block-slicedmenu-1 .slideleft').click(
			function() {

				if($('#block-slicedmenu-1 .menu').css('left') != '10px') {
					$('#block-slicedmenu-1 .menu').animate({"left": "+=" + (level2_length - 920 ) + "px"}, "slow");
				}
			}
		)
	}
	
	
	level3_length = 0;
	$('#block-slicedmenu-2 .menu li').each(
		function() {
			level3_length += $(this).width();
		}	
	)
	if(level3_length>940) {
		$('#block-slicedmenu-2 .content').wrap('<div id = "levelslider2"></div>');
		$("#levelslider2").append("<div class = 'slider slideright'>></div>");
		$("#levelslider2").append("<div class = 'slider slideleft'><</div>");
		$('#block-slicedmenu-2 .slideright').click(
			function() {
				if($('#block-slicedmenu-2 .menu').css('left') != "-" + (level3_length - 930  + "px")) {
					$('#block-slicedmenu-2 .menu').animate({"left": "-=" + (level3_length - 920 ) + "px"}, "slow");
				}
			}
		)
		$('#block-slicedmenu-2 .slideleft').click(
			function() {

				if($('#block-slicedmenu-2 .menu').css('left') != '10px') {
					$('#block-slicedmenu-2 .menu').animate({"left": "+=" + (level3_length - 920 ) + "px"}, "slow");
				}
			}
		)
	}
	
	
	
	// inline expendable items
	counter = 0;
	$('li.expandeble-item').each(function() { 
		$(this).attr('name' , counter);
		if(counter%2) {
		$(this).attr('class' , 'expandeble-item expandeble-item-section expand_item_'+ counter);
			$(this).hide();
			$(this).append(' | <a class = "expandeble_item_close" onclick = "$(\'.expand_item_' + (parseFloat($(this).attr('name')))+'\').hide();"> close</a>');
			$(this).click(function() {
				$('.expand_item_' + (parseFloat($(this).attr('name')) -1) + ' .expandable_item_plus').toggle();
				$('.expand_item_' + (parseFloat($(this).attr('name')) -1) + ' .expandable_item_minus').toggle();
			});
	
		}
		else {
			$(this).attr('class' , 'expandeble-item expandeble-item-link expand_item_'+ counter);
			$(this).prepend('<span class = "expandable_item_plus">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class = "expandable_item_minus">&nbsp;&nbsp;&nbsp;&nbsp;</span>');
			$('.expand_item_' + (parseFloat($(this).attr('name'))) + ' .expandable_item_minus').toggle();
			$(this).click(function() {
				$('.expand_item_' + (parseFloat($(this).attr('name')) + 1)).toggle();
				$('.expand_item_' + (parseFloat($(this).attr('name'))) + ' .expandable_item_plus').toggle();
				$('.expand_item_' + (parseFloat($(this).attr('name'))) + ' .expandable_item_minus').toggle();
			});
		}
		counter ++;
	});
	$('#home .panel-col-bottom>div').append('<div class = "clearer"></div>');
	$('#home .panel-col-bottom>div').wrap('<div class = "panel-col-bottom-container"></div>');
	$('.table_no_hearder').wrap('<div class = "table_no_hearder_level1"></div>');
	$('.table_no_hearder').wrap('<div class = "table_no_hearder_level2"></div>');

	// fix ie .table style issue - can not set background image to tbody
	$('.table').each(function() {
		$(this).wrap('<div class = "ie_table_fix"></div>');
	});
	$('.table tr:eq(1) td').each(function() {
		$(this).css('border-top','1px solid #1985C3');
	});
	$('.table td:last').each(function() {
		$(this).css('border-right','none');
	});
	
	$('.table100').each(function() {
		$(this).wrap('<div class = "ie_table_fix100"></div>');
	});
	$('.table100 tr:eq(1) td').each(function() {
		$(this).css('border-top','1px solid #1985C3');
	});
	$('.table100 td:last').each(function() {
		$(this).css('border-right','none');
	});
	
	$('.chart').each(function() {
		$(this).wrap('<div class = "chart_pre_0"><div class = "chart_pre_1"></div></div>');
	});
	
	$('.table:eq(0) tr:first-child td:last').css('border','none');
	$('.table:eq(0) tr:first-child td:first').css('background','url(/themes/tendu/images/table_caption_left.gif) no-repeat left bottom');
	$('.table:eq(0) tr:first-child td:last').css('background','url(/themes/tendu/images/table_caption_right.gif) no-repeat right bottom');
	
	$('.table:eq(1) tr:first-child td:last').css('border','none');
	$('.table:eq(1) tr:first-child td:first').css('background','url(/themes/tendu/images/table_caption_left.gif) no-repeat left bottom');
	$('.table:eq(1) tr:first-child td:last').css('background','url(/themes/tendu/images/table_caption_right.gif) no-repeat right bottom');
	
	$('.table:eq(2) tr:first-child td:last').css('border','none');
	$('.table:eq(2) tr:first-child td:first').css('background','url(/themes/tendu/images/table_caption_left.gif) no-repeat left bottom');
	$('.table:eq(2) tr:first-child td:last').css('background','url(/themes/tendu/images/table_caption_right.gif) no-repeat right bottom');
	
	$('.table:eq(3) tr:first-child td:last').css('border','none');
	$('.table:eq(3) tr:first-child td:first').css('background','url(/themes/tendu/images/table_caption_left.gif) no-repeat left bottom');
	$('.table:eq(3) tr:first-child td:last').css('background','url(/themes/tendu/images/table_caption_right.gif) no-repeat right bottom');
	
	
	$('.table100:eq(0) tr:first-child td:last').css('border','none');
	$('.table100:eq(0) tr:first-child td:first').css('background','url(/themes/tendu/images/table_caption_left.gif) no-repeat left bottom');
	$('.table100:eq(0) tr:first-child td:last').css('background','url(/themes/tendu/images/table_caption_right.gif) no-repeat right bottom');
	
	$('.table100:eq(1) tr:first-child td:last').css('border','none');
	$('.table100:eq(1) tr:first-child td:first').css('background','url(/themes/tendu/images/table_caption_left.gif) no-repeat left bottom');
	$('.table100:eq(1) tr:first-child td:last').css('background','url(/themes/tendu/images/table_caption_right.gif) no-repeat right bottom');
	
	$('.table100:eq(2) tr:first-child td:last').css('border','none');
	$('.table100:eq(2) tr:first-child td:first').css('background','url(/themes/tendu/images/table_caption_left.gif) no-repeat left bottom');
	$('.table100:eq(2) tr:first-child td:last').css('background','url(/themes/tendu/images/table_caption_right.gif) no-repeat right bottom');
	
	$('.table100:eq(3) tr:first-child td:last').css('border','none');
	$('.table100:eq(3) tr:first-child td:first').css('background','url(/themes/tendu/images/table_caption_left.gif) no-repeat left bottom');
	$('.table100:eq(3) tr:first-child td:last').css('background','url(/themes/tendu/images/table_caption_right.gif) no-repeat right bottom');
	
	
	
})

