function ___getPageScroll() {
    var xScroll, yScroll;
//    if (self.pageYOffset) {
//            yScroll = self.pageYOffset;
//            xScroll = self.pageXOffset;
    if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
            yScroll = document.documentElement.scrollTop;
            xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
            yScroll = document.body.scrollTop;
            xScroll = document.body.scrollLeft;
    }
    arrayPageScroll = new Array(xScroll,yScroll);
    return arrayPageScroll;
}

function ___getPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
            xScroll = window.innerWidth + window.scrollMaxX;
            yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
//    if (self.innerHeight) {	// all except Explorer
//            if(document.documentElement.clientWidth){
//                    windowWidth = document.documentElement.clientWidth;
//            } else {
//                    windowWidth = self.innerWidth;
//            }
//            windowHeight = self.innerHeight;
    if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
    }
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
            pageHeight = windowHeight;
    } else {
            pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
            pageWidth = xScroll;
    } else {
            pageWidth = windowWidth;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
    return arrayPageSize;
}


$(function(){
     $("div.viewport").innerHeight($("div.overview").height());
     $('#scrollbar1').tinyscrollbar({ axis: 'x', sizethumb: 122});
//    $('#scrollbar1').tinyscrollbar({ axis: 'x', sizethumb: 122});
    $('.slider > .viewport > .overview > ul > li').hover( function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
        
        $('#my_body').click(function(data){
            
             //$('#login_form').hide();
//             $('#searchHelp').hide();
           
        });

         $('#wrapper').click(function(){
             $('#searchHelp').hide();

        });
	$('#slideshow').anythingSlider({
			delay: 5000,
			animationTime : 1200
		});
	$('a#login_link').toggle(function() {
	  $('#login_form').show();
	}, function() {
	  $('#login_form').hide();
	});
	
	$('.catalog .tovar_item:nth-child(4n-3)').addClass('to_left');
	$('.catalog .tovar_item:nth-child(4n-2)').addClass('to_left');
	$('.catalog .tovar_item:nth-child(4n-1)').addClass('to_right');
	$('.catalog .tovar_item:nth-child(4n)').addClass('to_right');
	$('.catalog .tovar_item').hover(
	function(){
		var coords = $(this).offset();
		$(this).append($('<div id="tovar_hover"/>').html('test'));
		if($(this).hasClass('to_left')) 
		{
			$('#tovar_hover').css({left:coords.left+180,top:coords.top});
		}
		if($(this).hasClass('to_right')) 
		{
			$('#tovar_hover').css({left:coords.left-235,top:coords.top});
		}

	},
	function(){
		$('#tovar_hover').remove();
	});
	// sort bar dropdown menu
	$('.sort_bar select').addClass('invisible').wrap('<div class="sort_bar_select_wr" />');
	$('.sort_bar_select_wr').each(function(){
		var html = '';
		html+='<ul class="design_select">';
		$(this).find('option').each(function(){
			html+="<li ";
			if($(this).attr('selected')==$(this).attr('value')) html+=" class='selected'";
			html+="><a href='#' value='"+$(this).attr('value')+"' class='sort_click'>"+$(this).html()+"</a></li>";
		});
		html+='</ul>';
		$(this).append(html);
		
		if(!$(this).find('li.selected').size()) $(this).find('li:first-child').addClass('selected');	
		$(this).width($(this).find('li.selected').width());
	});
	$('.sort_click').live('click',function(){
		$(this).parents('.sort_bar_select_wr').find('select option:first-child').val($(this).attr('value')).change();
		$(this).parents('.sort_bar_select_wr').find('li.selected').removeClass('selected');
		$(this).parent().addClass('selected');	
		$(this).parents('.sort_bar_select_wr').width($(this).width());
		return false;
	});
		
	$('#search_text').click(function(){
		$('.search_help').show();
	});
	
	$('.tabs').tabs();

        $('.text_tabs').tabs();
	
	$('.gallery').tabs();
	
	var tabsText = $('.text_tabs').tabs({
           select: function(event, ui) { 
               if(ui.panel.id == 'text-tabs-3'){
                   $('#lastComments').hide();
               } else {
                   $('#lastComments').show();
               }
           }
        });
	$('#text-tabs-3-link').click(function(){
            tabsText.tabs( 'select', 'text-tabs-3'); return false;
        });
        $('#addCommetnRewrite').click(function(){
            tabsText.tabs( 'select', 'text-tabs-3'); 
            $('#sendComment').slideDown('slow');$('#addCommentButton').slideUp('slow');
            return false;
        });
	$('.catalog_item').live('mouseenter', function() {
		if(!$(this).parent().hasClass('vertical')) {
			$(this).addClass('hover_item');
			$(this).next().addClass('no_bg');
		}
	});
        $('.catalog_item').live('mouseleave ' , function() {
		if(!$(this).parent().hasClass('vertical')) {
			$(this).removeClass('hover_item');
			$(this).next().removeClass('no_bg');
		}
	});
	
	$('#menu > ul > li').hover( function() {
		$(this).addClass('menu_hover');
	}, function() {
		$(this).removeClass('menu_hover');
	});
	
	$('#menu > ul > li ul li').hover( function() {
		$(this).addClass('sub_menu_hover');
	}, function() {
		$(this).removeClass('sub_menu_hover');
	});
	
	$('#menu > ul > li ul li:first').css('border', '0 none');
	
	$('#menu > ul > li ul li:first').next().css('border', '0 none');
	
	$('.open_sub').hover( function() {
		$(this).children('.sort_sub').show();
	}, function() {
		$(this).children('.sort_sub').hide();
	});
	

	
//	$('.item_colors > li').hover( function() {
//		$(this).addClass('hover_color');
//	}, function() {
//		$(this).removeClass('hover_color');
//	});
	
	$('.params_table tr:odd').addClass('bg');
        
        $('.delivery > li > a').hover( function() {
		$(this).parent().next().addClass('no_bg');
	}, function() {
		$(this).parent().next().removeClass('no_bg');
	});
	
	$('.delivery li').each( function() {
		$(this).find('span').css('margin-top', function() {
			var marginTop = Math.floor(($(this).parent().height() - $(this).height())/2);
			return marginTop;
		});
	});
        
        if($('div').is('#gallery')){
		$("#gallery a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'normal',autoplay_slideshow: false, allow_resize: false, show_title: true});
	}
	
	var params = {
		changedEl: '.popup_form select',
		visRows: 5,
		scrollArrows: true,
		checkZIndex: true
	}
	cuSel(params);

        var params_2 = {
		changedEl: '.form select',
		visRows: 5,
		scrollArrows: true,
		checkZIndex: true
	}
	cuSel(params_2);

	
	$('.compare tr:odd').addClass('bg');

	$('.compare tr:last').addClass('last_row');

	$('.compare tr').each( function() {
		$(this).children('td:last').addClass('last');
	});

	$('.compare td').hover( function() {
		var i = $(this).index();
		if(i!=0){
			$('.compare tr').each( function() {
				$(this).children('td').each( function(ind) {
					if(ind == i) {
						$(this).addClass('cell_hover');
						$(this).next().addClass('cell_hover_neighbor');
					}
				});
			});
		}
	}, function() {
		$('.compare tr td').removeClass('cell_hover');
		$('.compare tr td').removeClass('cell_hover_neighbor');
	});
		
});
