$(document).ready(function(){
	
	$("select.select_material").live( "change" , function() {
		//if( $iw_current ) iw_current_hide();
		$this = $(this);
		if( $this.val() != '' ) {
			//window.open( $this.val() );
			document.location.href = $this.val();
		}
	});
	
	try {
	$('#ts_mat_filter select').sSelect({
		'ddMaxHeight':200,
		'listWidthSettings':{
			'[name=mat_id]' : '400px'
		}
	});}
	catch(e){}
	
	try {
	$('select.select_material').sSelect({
		'ddMaxHeight':200,
		'listWidthSettings':{
			'.select_material' : '300px'
		}
	}).change(function(e){document.location.href = $(e.target).val();/*window.open( $(e.target).val())*/});
	}
	catch(e){}
	
	//$('#ts_mat_filter select').SBR();
	
	//$('#ts_mat_filter select[name=mat_id]').selectbox();
	//$('#ts_mat_filter select').selectbox();
	
	/*var _cnt=$('#ts_mat_filter select').length;
	for(var i=0; i<_cnt; i++)
		$('#ts_mat_filter select').eq(i).selectbox();/**/
	
	//$('#ts_mat_filter select[name=mat_id]').combobox();
	//$('#ts_mat_filter select').combobox();
	/*
	var $combobox_selects = $('#ts_mat_filter select'), combobox_selects_length = $combobox_selects.length;
	for(var i=1; i<combobox_selects_length; i++)
		$combobox_selects.eq(i).combobox(
					{
						comboboxContainerClass: "comboboxContainer",
						comboboxValueContentContainerClass: "comboboxValueContainer",
						comboboxValueContentClass: "comboboxValueContent",
						comboboxDropDownClass: "comboboxDropDownContainer",
						comboboxDropDownButtonClass: "comboboxDropDownButton",
						comboboxDropDownItemClass: "comboboxItem",
						comboboxDropDownItemHoverClass: "comboboxItemHover"
					});
	/**/
	
	var tmp_on_login_form_clicked = false;
	$("div.topMenuCabinet").click( function(event) {
		$("#loginForm").show();
		$("#menu_cabinet" ).addClass( "active" );
		return false;
		});
	$("body").click( function() {
		if( !tmp_on_login_form_clicked) {
			$("#loginForm").hide();
			$("#menu_cabinet" ).removeClass( "active" );
			}
		tmp_on_login_form_clicked = false;
		});
	$("#loginForm").click( function(event) {
		tmp_on_login_form_clicked = true;
		});
		
	$("#otherSite").change( function() {
		tmp_val = $(this).val();
		if( tmp_val ) {
			$tmp_form = $("#otherSites");
			if( $tmp_form.length ) {
				$tmp_form.attr( "action" , tmp_val );
				$tmp_form.submit();
				}
			}
		} );
	
	$bord_left_divs = $( "div.bord_left" );
	if( $bord_left_divs.length ) {
		$bord_left_divs.each( function() {
			$bord_left = $(this);
			$bord_pro = $( "div.bord_pro" , $bord_left );			
			if( $bord_pro.length ) {
				$bord_scroll = $( "div.bord_scroll" , $bord_left );			
				$but_top = $( "div.but_top" , $bord_left );
				//alert( $but_top.length );
				$but_bot = $( "div.but_bot" , $bord_left );
				
				bord_real_height = parseInt( $bord_scroll.height() );
				bord_height = parseInt( $bord_pro.height() );
				bord_current_top = 0;
				bord_step = 20;
				
				$but_bot.click( function() {
					if( ( bord_current_top + bord_height ) < bord_real_height ) {
						$bord_scroll.css( "margin-top" , - ( bord_current_top + bord_step ) );
						bord_current_top += bord_step;
						
						bord_left_divs_check();
						}
					} );
				
					
				$but_top.click( function() {
					if( bord_current_top > 0 ) {
						$bord_scroll.css( "margin-top" , - ( bord_current_top - bord_step ) );
						bord_current_top -= bord_step;
						
						bord_left_divs_check();
						}
					} );
					
				function bord_left_divs_check( ) {
					if( bord_current_top > 0 ) { $but_top.addClass( "but_top_activ" ) } else { $but_top.removeClass( "but_top_activ" ) }
					if( ( bord_current_top + bord_height ) < bord_real_height ) { $but_bot.removeClass( "but_bot_activ" ) } else { $but_bot.addClass( "but_bot_activ" ) }
					}
				}
			
			});
		//alert( 'dd' );
		
		}
});

function GB_random_elements( place_name_lat , count_objects , max_count ) {
    //alert( max_count );
    //alert( place_name_lat );
    var min_random = 0;
    var max_random = count_objects;
    var range = max_random - min_random;
    var random = null;
    var used_randoms = new Array();
    var max_attempts;
    
    for( var k = 0 ; k < max_count ; k++ ) {
        max_attempts = 50;
        while( ( random === null || $.inArray( random , used_randoms ) !== -1 ) && --max_attempts > 0 ) {
            random = Math.floor( Math.random() * range ) + min_random;
            //random = 0;
            }
        
        
        //alert( $('#".$place_name_lat."_' + GB_random ).html() );
        used_randoms[ used_randoms.length ] = random;
        $( '#' + place_name_lat + '_container' ).append( $( '#' + place_name_lat + '_' + random ).html() );
        }
    }
