jQuery(document).ready(function($){
	
	$('#quickSearchStyledSelect').styledSelect();
	
	// LavaLamp NAV
	calculte_nav_width(); // call this before lavaLamp
	
	$("#nav ul").lavaLamp({
		fx: "easeOutExpo",
		speed: 800
	});
	// END LavaLamp NAV
	
	
	// Set captcha by JS
	$("input[name='cap_prot']").val('1');
	
	// Datepicker
	$('#form_published_from, #form_published_to, #form_date_end_from, #form_date_end_to').each(function(){
		$(this).datepicker({
			dateFormat: 'dd/mm/yy'
			,inline: true
			,showOn: 'both' //both or button
			,buttonImage: '/images/common/calendar-icon.gif'
			,buttonImageOnly: true
		});
	});
	
	
	$(".search_advanced_results_table tr").not('.heading').hover(function(){
		$(this).addClass('selected');
	},function(){
		$(this).removeClass('selected');
	});
	
	
	bindAdvancedSearchEvents();
	
	
	buttonOverState('.buttonCommon_200', 'buttonCommon_200_selected');
	buttonOverState('.buttonCommon_140', 'buttonCommon_140_selected');
	buttonOverState('.buttonCommon_120', 'buttonCommon_120_selected');
	buttonOverState('.buttonCommon_small_120', 'buttonCommon_small_120_selected');
	buttonOverState('.buttonCommon_100', 'buttonCommon_100_selected');
	
	// change plans
	$('.abonament .plan_disabled').animate({ opacity: 0.6 }, "fast"); // For IE8 we need to apply same Opacity to ".abonament .plan_disabled .price_box" but we may need to change background image to GIF or PNG 8-bit. Now it is PNG 24-bit
	
});

function calculte_nav_width()
{
	var total_width = 0;
	$("#nav ul li").each(function(){
		total_width = total_width + $(this).width();
	});
	if(total_width>0) {
		$("#nav ul").width(total_width);
		//alert(total_width);
	}
}

/* OnOver - add clas for IE - Should be used on elements different from Links */
function buttonOverState(selector, className)
{
	/* Hover over the login button */
	$(selector).hover(function(){
		$(this).addClass(className);
	},
	function(){
		$(this).removeClass(className);
	});
}

function bindAdvancedSearchEvents()
{
	/* Attempt for IE6 alternative - also didn't working with Label tags */
	/*
	$(".tender_type_0 input").bind( "change", function() {
		if( $(this).is(":checked") ) {
			// if checked - we should uncheck all others?
			$(".tender_type_1 input").removeAttr("checked");
		}
	});
	$(".tender_type_1 input").bind( "change", function() {
		// if one of the others elements are marked
		//alert($(this));
		$(".tender_type_1 input").each(function(){
			//alert($(this));
			if( $(this).is(":checked") ) {
				$(".tender_type_0 input").removeAttr("checked");
				//break; // this is not working inside jquery each() loop - we should use "return false;": http://api.jquery.com/each/
				return false;
			}
		});
	});
	return;
	*/
	
	$(".tender_type_0").bind( "click", function() {
		/*
		if( $("input", this).is(":checked") ) {
			alert('checked');
		}
		if( $("input", this).val()==1 ) {
			alert('value: 1');
		}
		*/
		if( $("input", this).is(":checked") ) {
			// if checked - we should uncheck all others?
			$(".tender_type_1 input").removeAttr("checked");
		}
	});
	$(".tender_type_1").bind( "click", function() {
		if( $("input", this).is(":checked") ) {
			// if checked - we should uncheck all others?
			$(".tender_type_0 input").removeAttr("checked");
		}
	});
	$(".tender_place_0").bind( "click", function() {
		if( $("input", this).is(":checked") ) {
			// if checked - we should uncheck all others?
			$(".tender_place_1 input").removeAttr("checked");
		}
	});
	$(".tender_place_1").bind( "click", function() {
		if( $("input", this).is(":checked") ) {
			// if checked - we should uncheck all others?
			$(".tender_place_0 input").removeAttr("checked");
		}
	});
	$(".tender_cat_0").bind( "click", function() {
		if( $("input", this).is(":checked") ) {
			// if checked - we should uncheck all others?
			$(".tender_cat_1 input").removeAttr("checked");
		}
	});
	$(".tender_cat_1").bind( "click", function() {
		if( $("input", this).is(":checked") ) {
			// if checked - we should uncheck all others?
			$(".tender_cat_0 input").removeAttr("checked");
		}
	});
	return false;
	
	// IE6 cannot Toggle() the selected checkbox when clicked on the its Label
}

/*
http://jivebay.com/2007/05/30/handling-checkboxes-radio-buttons-and-select-options-in-jquery/

$("input[@name='option_linkwindow']").click(
	function()
	{
		if ($("input[@name='option_linkwindow']").is(":checked"))
			$(".feed/ul>li/a").attr("target","_blank");
		else
			$(".feed/ul>li/a").attr("target","_self");
		$(this).blur();
	}
);



*/


