$(document).ready( function(){


	$('.manuf').click(function () {
		var cs = $('.manuf_off').attr('checked');
		if (cs == 1) {
			$('.manuf_off').attr('checked', !this.checked);
		};
		
		var size = $('.manuf:checked').length;
		if(size == 0){
			$('.manuf_off').attr('checked', true);
		};
		
	});
	$('.manuf_off').click(function () {
		var cs = $('.manuf_off').attr('checked');	
		if (cs == 1) {
			$('.manuf').attr('checked', 0);
		}else{
			var size = $('.manuf:checked').length;
			if(size == 0){
				$('.manuf_off').attr('checked', true);
			};
		};
		
	});
	
	$('.count').click(function () {
		var cs = $('.count_off').attr('checked');
		if (cs == 1) {
			$('.count_off').attr('checked', !this.checked);
		};
		
		var size = $('.count:checked').length;
		if(size == 0){
			$('.count_off').attr('checked', true);
		};
		
	});
	
	$('.count_off').click(function () {
		var cs = $('.count_off').attr('checked');	
		if (cs == 1) {
			$('.count').attr('checked', 0);
		}else{
			var size = $('.count:checked').length;
			if(size == 0){
				$('.count_off').attr('checked', true);
			};
		};
	});
	
	$('.avail').click(function () {
		var cs = $('.avail_off').attr('checked');
		if (cs == 1) {
			$('.avail_off').attr('checked', !this.checked);
		};
		
		var size = $('.avail:checked').length;
		if(size == 0){
			$('.avail_off').attr('checked', true);
		};
		
	});
	
	$('.avail_off').click(function () {
		
		var cs = $('.avail_off').attr('checked');	
		
		if (cs == 1) {
			$('.avail').attr('checked', 0);
		}else{
			var size = $('.avail:checked').length;
			if(size == 0){
				$('.avail_off').attr('checked', true);
			};
		};
		
	});
	
	$('.color').click(function () {
		var cs = $('.color_off').attr('checked');
		if (cs == 1) {
			$('.color_off').attr('checked', !this.checked);
		};
		
		var size = $('.color:checked').length;
		if(size == 0){
			$('.color_off').attr('checked', true);
		};
		
	});
	
	$('.color_off').click(function () {
		var cs = $('.color_off').attr('checked');	
		if (cs == 1) {
			$('.color').attr('checked', 0);
		}else{
			var size = $('.color:checked').length;
			if(size == 0){
				$('.color_off').attr('checked', true);
			};
		};
				
	});
	
	
	$('.osobennosti').click(function () {
		var cs = $('.osobennosti_off').attr('checked');
		if (cs == 1) {
			$('.osobennosti_off').attr('checked', !this.checked);
		};
		
		var size = $('.osobennosti:checked').length;
		if(size == 0){
			$('.osobennosti_off').attr('checked', true);
		};
		
	});
	
	$('.osobennosti_off').click(function () {
		
		var cs = $('.osobennosti_off').attr('checked');	
		
		if (cs == 1) {
			$('.osobennosti').attr('checked', 0);
		}else{
			var size = $('.osobennosti:checked').length;
			if(size == 0){
				$('.osobennosti_off').attr('checked', true);
			};
		};
		
	});
	
	
	
	$('.cost').click(function () {
		var cs = $('.cost_off').attr('checked');
		if (cs == 1) {
			$('.cost_off').attr('checked', !this.checked);
		};
		
		var size = $('.cost:checked').length;
		if(size == 0){
			$('.cost_off').attr('checked', true);
		};
		
	});
	
	$('.cost_off').click(function () {
		var cs = $('.cost_off').attr('checked');	
		if (cs == 1) {
			$('.cost').attr('checked', 0);
		}else{
			var size = $('.cost:checked').length;
			if(size == 0){
				$('.cost_off').attr('checked', true);
			};
		};
	});
	
	
	
	
	/*
	$('.fl-button').click(function () {
	
		var data = right();
		
		//alert(data);
		
		$.ajax({
	        type: 'POST',
	        url: '/ajax/section/',
	        data: data,   
	        success: function(html){
	        	$('.ct-item').remove();
	        	$('#pagesdiv').remove();
	            $('#ct-content').html('');
	            $('#ct-content').append(html);
	        }
		})	        
	});
	
	function right() {
		
		var all = String;
		
		//производитель
		var id = $('.manuf_off').attr('checked');
		if (id == false) {
			
			var manufCheckbox = $('.manuf');
			var manufItem = new Array();
			var x = 0;
		
			for (i=0;i<manufCheckbox.length;i++) {
			
				if ($(manufCheckbox[i]).attr('checked') == true) {
					
					var manufId = explode('_', $(manufCheckbox[i]).attr('id'));
					manufItem[x] = manufId[1];
					x++;
				}
			};
			
			var manufAll = 'manuf='+manufItem;
			
 		}else{
 		
 			var manufCheckbox = $('.manuf');
			var manufItem = new Array();
			var x = 0;
		
			for (i=0;i<manufCheckbox.length;i++) {
			
				if ($(manufCheckbox[i]).attr('checked') == false) {
					
					var manufId = explode('_', $(manufCheckbox[i]).attr('id'));
					manufItem[x] = manufId[1];
					x++;
				}
			};
			
			var manufAll = 'manuf='+manufItem;
			 		
 		};
 		
 		
 		//страна
		var id = $('.count_off').attr('checked');
		if (id == false) {
			
			var countCheckbox = $('.count');
			var countItem = new Array();
			var x = 0;
		
			for (i=0;i<countCheckbox.length;i++) {
			
				if ($(countCheckbox[i]).attr('checked') == true) {
					
					var countId = explode('_', $(countCheckbox[i]).attr('id'));
					countItem[x] = countId[1];
					x++;
				}
			};
 		};
 		var countAll = 'count='+countItem;
 		
 		
 		//наличие
 		var id = $('.avail_off').attr('checked');
		if (id == false) {
			
			var availCheckbox = $('.avail');
			var availItem = new Array();
			var x = 0;
		
			for (i=0;i<availCheckbox.length;i++) {
			
				if ($(availCheckbox[i]).attr('checked') == true) {
					
					var availId = explode('_', $(availCheckbox[i]).attr('id'));
					availItem[x] = availId[1];
					x++;
				}
			};
 		};
 		var availAll = 'avail='+availItem;
 		
 		
 		//цвет
 		var id = $('.color_off').attr('checked');
		if (id == false) {
			
			var colorCheckbox = $('.color');
			var colorItem = new Array();
			var x = 0;
		
			for (i=0;i<colorCheckbox.length;i++) {
			
				if ($(colorCheckbox[i]).attr('checked') == true) {
					
					var colorId = explode('_', $(colorCheckbox[i]).attr('id'));
					colorItem[x] = colorId[1];
					x++;
				}
			};
 		};
 		var colorAll = 'color='+colorItem;
 		
 		
 		//особенности
 		var id = $('.osobennosti_off').attr('checked');
		if (id == false) {
			
			var osobennostiCheckbox = $('.osobennosti');
			var osobennostiItem = new Array();
			var x = 0;
		
			for (i=0;i<osobennostiCheckbox.length;i++) {
			
				if ($(osobennostiCheckbox[i]).attr('checked') == true) {
					
					var osobennostiId = explode('_', $(osobennostiCheckbox[i]).attr('id'));
					osobennostiItem[x] = osobennostiId[1];
					x++;
				}
			};
 		};
 		var osobennostiAll = 'osobennosti='+osobennostiItem;
 		
 		
 		//стоимость
 		var id = $('.cost_off').attr('checked');
		if (id == false) {
			
			var costCheckbox = $('.cost');
			var costItem = new Array();
			var x = 0;
		
			for (i=0;i<costCheckbox.length;i++) {
			
				if ($(costCheckbox[i]).attr('checked') == true) {
					
					var costId = explode('_', $(costCheckbox[i]).attr('id'));
					costItem[x] = costId[1];
					x++;
				}
			};
 		};
 		var costAll = 'cost='+costItem;
		
		//url
		var url = $('.uri').attr('value');
		var urlAll = 'url='+url;
		
		//все вместе
		all = manufAll+'&'+countAll+'&'+availAll+'&'+colorAll+'&'+osobennostiAll+'&'+costAll+'&'+urlAll;
		
		//alert(all);
		
		return all;
	};
	*/
	
	$('.roomsend').click(function () {
	
		var data = String;
		
		var itemid = $(this).attr('id');

		data = 'id='+itemid;
		
		$.ajax({
	        type: 'POST',
	        url: '/room/update/',
	        data: data,   
	        success: function(html){
	        	$('.ico-room').remove();
	        	$('#ico-room').append(html);
	        	$('#upEvent').fadeIn("fast");
	        	setTimeout("$('#upEvent').fadeOut()", 1500);
	        }
		})	        
	});
	
	$('.roomsoff').click( function () {
	
		var data = String;
		
		var itemid = $(this).attr('id');

		data = 'id='+itemid;
				
		$.ajax({
	        type: 'POST',
	        url: '/room/delete/',
	        data: data,   
	        success: function(html){
	        	$('.ct-item').remove();
	        	$('#ct-content').append(html);
	        }
		})
			
	});
	
});


function rollover(x){

	$("#m" + x + " > img").attr('src', '/pdir/menu/' + roll[x]);
}

function rolloverback(x){
	$("#m" + x + " > img").attr('src', '/pdir/menu/' + pic[x]);
}

function explode( delimiter, string ) { // Split a string by string
    //
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: kenneth
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
 
    var emptyArray = { 0: '' };
 
    if ( arguments.length != 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
 
    return string.toString().split ( delimiter.toString() );
}
