var clientCoords = function() {
     var dimensions = {width: 0, height: 0};
     if (document.documentElement) {
         dimensions.width = document.documentElement.offsetWidth;
         dimensions.height = document.documentElement.offsetHeight;
     } else if (window.innerWidth && window.innerHeight) {
         dimensions.width = window.innerWidth;
         dimensions.height = window.innerHeight;
     }
     return dimensions;
};

$(window).bind('load', function(){
if ($('.scrollGallery ul').attr('id'))
    {
			$('div.scrollGallery').mouseGallerySlide({
				scrollElParent: 'ul',
				scrollEl: 'li'	
			});
	}
});


var current_left_border = 'def_left_border';
var current_right_border = 'def_right_border';
var current_bottom_left = 'def_bottom_left';
var current_bottom = 'def_bottom';
var current_text = 'def_text';

var logo_images = new Array();

$(document).ready(function() { 
	
	
	var current_logo = $('.logo_container img').attr('src');
	if (current_logo)
	{
		

		var new_src = current_logo.replace(".png","_black.png");
	
		logo_images['bg_white'] = new Image();
		logo_images['bg_white'].src = current_logo;
		
		logo_images['bg_black'] = new Image();
		logo_images['bg_black'].src = new_src;
		
		new_src = current_logo.replace(".png","_texture.png");
		logo_images['bg_texture'] = new Image();
		logo_images['bg_texture'].src = new_src;
		
		
		$('.bg_changer div').click(function(){
	    	$('#left_content').css({'background-color' : $(this).css('background-color'), 'background-image' : $(this).css('background-image')});
	    	var this_class = $(this).attr('class');
	    	var class_name = this_class + '_left_border';
	    	$('#left_content').removeClass(current_left_border).addClass(class_name);
	    	current_left_border = class_name;
	    	
	    	class_name = this_class + '_right_border';
	    	$('#right_content1').removeClass(current_right_border).addClass(class_name);
	    	current_right_border = class_name;
	    	
	    	class_name = this_class + '_left';
	    	$('#bottom_left1').removeClass(current_bottom_left).addClass(class_name);
	    	current_bottom_left = class_name;
	    	
	    	class_name = this_class + '_bottom';
	    	$('#bottom_left2').removeClass(current_bottom).addClass(class_name);
	    	current_bottom = class_name;
	    	
	    	
	    	if (this_class == 'bg_texture')
	    	{
	    		class_name = this_class + '_text';
	    	}
	    	else
	    	{
	    		class_name = 'def_text';
	    	}
	    	$('#text').removeClass(current_text).addClass(class_name);
	    	current_text = class_name;
	    	
	    	
	    	
	    	$('.logo_container img').attr('src',logo_images[this_class].src);
	
	    });
	    
	}
    
    if ($('.scrollGallery ul').attr('id'))
    {
    	$('li img',$(this)).load(function(){
			//alert(this.height);
		});
		
//		$('div.scrollGallery').mouseGallerySlide({
//			scrollElParent: 'ul',
//			scrollEl: 'li'
//		});
    }
    
    
    
    
    if ($('.click').attr('id'))
    {
    	$('.sub_item').addClass('nodisplay');
    	
    	$('.click').mouseover(function(){
    		$(this).addClass('click_hover');
    	}).mouseout(function(){
    		$(this).removeClass('click_hover');
    	}).click(function(){
    		var parent_id = $(this).attr('id');
    		show_child(parent_id);
    	});
    	
    	$('.q').mouseover(function(){
    		$(this).attr('can_out',0);
    		$(this).animate( { fontSize:"20px", paddingTop: 0 },0 , '', function(){ 
    			$(this).attr('can_out',1);
    			if ($(this).attr('must_out') == 1)
    				$(this).animate( { fontSize:"18px",paddingTop: '2px'}, 0 );
    		})
    	}).mouseout(function(){
    		if ($(this).attr('is_active') != 1)
    		{
	    		if ($(this).attr('can_out') == 1)
	    		{
	    			$(this).animate( { fontSize:"18px",paddingTop: '2px'}, 0 )
	    			$(this).attr('must_out',0);
	    		}
	    		else
	    		{
	    			$(this).attr('must_out',1);
	    		}
    		}
    	});
    	
    	$('li.s').mouseover(function(){
    		$(this).attr('can_out',0);
    		$(this).animate( { fontSize:"16px", paddingTop: 0 }, 0 , '', function(){ 
    			$(this).attr('can_out',1);
    			if ($(this).attr('must_out') == 1)
    				$(this).animate( { fontSize:"16px",paddingTop: '2px'}, 0 )
    		})
    	}).mouseout(function(){
    		//if ($('span',$(this)).attr('is_active') != 1)
    		{
	    		if ($(this).attr('can_out') == 1)
	    		{
	    			$(this).animate( { fontSize:"16px",paddingTop: '2px'}, 0 );
	    			$(this).attr('must_out',0);
	    		}
	    		else
	    		{
	    			$(this).attr('must_out',1);
	    		}
    		}
    	});
    }
    
	
});

var current_parent_id = 'q1';
var cur_q = 'q0';
var cur_s = 's0';
var cur_w = 'w0';
var cur_t = 't0';

var opened = new Array();
var opened_count = 0;


function show_child(parent_id)
{
	if(parent_id.indexOf('s') == -1)
	{//при нажатии на элемент верхнего уровня
		if (cur_q != parent_id)
		{
			$('#'+cur_q+'s').addClass('nodisplay');
			$('#'+cur_s+'w').addClass('nodisplay');
			$('#'+cur_t+'t').addClass('nodisplay');
			$('#'+cur_q).removeClass('item_active');
			$('#'+cur_q).removeClass('q_active');
			$('#'+cur_s).removeClass('item_active');
			$('#'+cur_s).removeClass('s_active');
			$('#'+cur_t).removeClass('item_active');
			$('#'+cur_q).attr('is_active',0).animate( { fontSize:"18px",paddingTop: '2px'}, 0 );
			
	
			$('#'+parent_id+'s').removeClass('nodisplay');
			$('#'+parent_id).addClass('item_active');
			$('#'+parent_id).addClass('q_active');
			$('#'+parent_id).attr('is_active',1);
			cur_q = parent_id;
			
			$('#'+cur_s).attr('is_active',0);
			cur_s = 's0';
		}
	}
	else if (parent_id.indexOf('w') == -1)
	{//при нажатии на элемент второго уровня
		if (cur_s != parent_id)
		{
			$('#'+cur_s+'w').addClass('nodisplay');
			$('#'+cur_t+'t').addClass('nodisplay');
			$('#'+cur_s).removeClass('item_active');
			$('#'+cur_s).removeClass('q_active');
			$('#'+cur_w).removeClass('item_active');
			$('#'+cur_s).removeClass('s_active');
			$('#'+cur_t).removeClass('item_active');
			//$('#'+cur_s).attr('is_active',0).animate( { fontSize:"16px",paddingTop: '2px'}, 0 );
			
			$('#'+parent_id+'w').removeClass('nodisplay');
			$('#'+parent_id).addClass('item_active');
			$('#'+parent_id).addClass('s_active');
			$('#'+parent_id).attr('is_active',1);
			cur_s = parent_id;
		}
	}
	else if (parent_id.indexOf('t') == -1)
	{//при нажатии на элемент третьего уровня
		$('#'+cur_t+'t').addClass('nodisplay');
		$('#'+cur_t).removeClass('item_active');
		
		$('#'+parent_id+'t').removeClass('nodisplay');
		$('#'+parent_id).addClass('item_active');
		cur_t = parent_id;
	}
	
	
}