﻿$(document).ready(function() {
// Show card user
var box = $('#personal_cabinet');
        var link = $('#show_card_user');

        link.click(function() {
            box.show(150); return false;
        });

        $(document).click(function() {
            box.hide(150);
        });

        box.click(function(e) {
            e.stopPropagation();
        });



// Submenu
 var mh = $('#submenu li.active a').height();
 var mw = $('#submenu li.active a').width();
 $('#submenu li.active').append('<div class="mbg"><div class="mbg_bl"><div class="mbg_tr"><div class="mbg_br"></div></div></div></div>');
 $('#submenu li.active .mbg_br').height(mh+8);
 $('#submenu li.active .mbg_br').width(mw+15);
 
// Hide blocks
 $(window).resize(function() {
  if($('#photocatalogue1').width()<654) {$('#photocatalogue1 .pc1_item:eq(4)').css({'display' : 'none'});} else {$('#photocatalogue1 .pc1_item:eq(4)').css({'display' : '-moz-inline-box', 'display' : 'inline-block'});};
});

// Authentication window
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;
			} else 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;
		};
		
$(window).resize(function() {
				// Get page sizes
				var arrPageSizes = ___getPageSize();
				// Style overlay and show it
				$('#curtain').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
				});
				
			});

var arrPageSizes = ___getPageSize();
			// Style overlay and show it
			$('#curtain').css({
				//backgroundColor:	"#000",
				//opacity:			0.9,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
			}).fadeIn(1000);

$("#enter_pl").click(function () {
		  $('body').append(LoginBox);	
          var arrPageSizes = ___getPageSize();
			// Занавес
			$('#curtain').css({
				backgroundColor:	"#000",
				opacity:			0.3,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
			});
			$('#curtain').click(function() {
								 
				_finish();									
			});
          return false;
        }); 
function _finish() {
			$('#order-form-box').remove();
			$('#curtain').fadeOut(function() { $('#curtain').remove(); });
		}


// Text col
if ($('.two_columns5 .big_photo').length == 1) {  
    
	var pw = $('.two_columns5 .big_photo').width()+2
	
	$('.no_resizing_column5').width(pw)
	var minus = "-"
	$('.resizing_column5').attr("style","margin-left: -"+pw+"px")
	
	$('.resizing_column5_content').css({'margin-left' :  pw + 14});
}

// Fucking comments

if ($('#five_comments .one_comment').length > 5) { 
	var commentsSum = $('#five_comments .one_comment').length 
	var comments_sum_height = 0
	var five_comments_sum_height = 0
    var one_comment_height = 0
  
	for (var i = 0; i < 5; i++) {
		one_comment_height = $('#five_comments .one_comment:eq('+ i +')').height()+15;
		five_comments_sum_height = five_comments_sum_height + one_comment_height;
	}
	
	$('#five_comments').height(five_comments_sum_height);
	$("#all_reviews>span").click(function(){
		$("#del_all_reviews").hide(200);							  
		for (var i = 0; i < commentsSum; i++) {
			one_comment_height = $('#five_comments .one_comment:eq('+ i +')').height()+15;
			comments_sum_height = comments_sum_height + one_comment_height;
		}
		$('#five_comments').animate({ 
				height: comments_sum_height,
				opacity: 1.0
		},  200, 'linear'); 
		
	
	}); 
}

var fh = $('#form_height').height();
$('#latent_form').height(0);
$("#add_comment>span").click(function(){							  
		$("#del_add_comment").hide(200);							  
		$('#latent_form').animate({ 
				height: fh,
				opacity: 1.0
		},  200, 'linear'); 
		
	
	}); 
// Fucking Users
if ($('#users_list_height a').length) { 
	//alert($('#users_list_height a:eq(0)').height())
	
	var user_link_height = $('#users_list_height a:eq(0)').css('line-height')
	var all_users_links_sum = $('#users_list_height').height()
	
	$('#users_list').height(parseFloat(user_link_height)*2);
	
	$("#del_all_interest_holders>span").click(function(){							  
		$("#del_all_interest_holders").hide(100);							  
		$('#users_list').animate({ 
				height: all_users_links_sum,
				opacity: 1.0
		},  100, 'linear'); 
		
	
	}); 
}
// Fucking Tables
var all_banks_lenght = $('#all_banks .green_box_table').length
for (var i = 0; i < all_banks_lenght; i++) {
	var table_link = $('#all_banks .green_box_table:eq('+ i +') .table2')
	var table_box_link = $('#all_banks .green_box_table:eq('+ i +')')
	var table_height = table_link.height()
	var tr_sum = $('#all_banks .green_box_table:eq('+ i +') .table2 tr').length;
	if (tr_sum > 4) { //alert(tr_sum)
			var tr_sum_height = 0
			for (var a = 0; a < 4; a++) {
				var one_tr_height = table_link.find('tr:eq('+ a +')').height()
				tr_sum_height = tr_sum_height + one_tr_height;
				
			}
	$('#all_banks .green_box_table:eq('+ i +')').height(tr_sum_height)
	table_box_link.next().css({'display' : 'block'});
	};			
}


	$(".all_offers_bank").click(function(){
		var tr_sum = $(this).parent().prev().find('.table2 tr').length;
		if (tr_sum > 4) { 
			var table_height = $(this).parent().prev().find('.table2').height()
			var tr_sum_height = 0
			/*for (var i = 0; i < 4; i++) {
				one_tr_height = $(this).parent().prev().find('.table2 tr:eq('+ i +')').height();
				tr_sum_height = tr_sum_height + one_tr_height;
				alert(tr_sum_height)
			}*/
			
			$(this).parent().prev().animate({ 
				height: table_height
				//opacity: 1.0
		},  100, 'linear');
			$(this).parent().hide(100)
		};								 
										 
		//$(this).parent().prev().css('border','1px solid red')
		
	}); 
// Fucking question_of_the_day
$('#question_of_the_day').height(parseFloat($('#question_of_the_day_height').css('line-height'))*3)
$("#more_downwards1>span").click(function(){$("#more_downwards1").hide(100); $('#question_of_the_day').animate({height: $('#question_of_the_day_height').height()},  100, 'linear');})
});
	

