// JavaScript Document
$(document).ready(function() {	
	$("#firstnews-scroll").jCarouselLite({
        btnNext: ".first-news .next",
        btnPrev: ".first-news .previous",
		visible: 3,
		scroll: 3,
		start: 0
    });

	$("#note-slider").jCarouselLite({
	btnNext: "#note .title .forground .previous",
	btnPrev: "#note .title .forground .next",
	auto: 5800,
		visible: 1,
		start: 0,
		afterEnd: function(a) {
			b = $(a).attr('numb');
			$('#note .title .forground .count .numb').html(b);
		}
    });

    $("#note1-slider").jCarouselLite({
    btnNext: "#note1 .title .forground .previous",
    btnPrev: "#note1 .title .forground .next",
	auto: 5800,
        visible: 1,
        start: 0,
        afterEnd: function(a) {
            b = $(a).attr('numb');
            $('#note1 .title .forground .count .numb').html(b);
        }
    });
    $("#note2-slider").jCarouselLite({
    btnNext: "#note2 .title .forground .previous",
        btnPrev: "#note2 .title .forground .next",
	auto: 5800,
        visible: 1,
        start: 0,
        afterEnd: function(a) {
            b = $(a).attr('numb');
            $('#note2 .title .forground .count .numb').html(b);
        }
    });
    $("#note3-slider").jCarouselLite({
    btnNext: "#note3 .title .forground .previous",
    btnPrev: "#note3 .title .forground .next",
	auto: 5800,
        visible: 1,
        start: 0,
        afterEnd: function(a) {
            b = $(a).attr('numb');
            $('#note3 .title .forground .count .numb').html(b);
        }
    });

	$('#photo-slider ul li .photo-cont .titr-cont').hide();
	
	$("#photo-slider").jCarouselLite({
        btnNext: "#photo .title .forground .next",
        btnPrev: "#photo .title .forground .previous",
		visible: 1,
		start: 0,
		auto: 5000,
		beforeStart: function(a) {
			$(a).find('.photo-cont').find('.titr-cont').hide();
		},
		afterEnd: function(a) {
			$(a).find('.photo-cont').find('.titr-cont').slideDown();
			b = $(a).attr('numb');
			$('#photo .title .forground .count .numb').html(b);
		}
    });
	
	$('#multi-slider ul li .photo-cont .titr-cont').hide();
	
	$("#multi-slider").jCarouselLite({
        btnNext: "#multi .title .forground .next",
        btnPrev: "#multi .title .forground .previous",
		visible: 1,
		start: 0,
		beforeStart: function(a) {
			$(a).find('.photo-cont').find('.titr-cont').hide();
		},
		afterEnd: function(a) {
			$(a).find('.photo-cont').find('.titr-cont').slideDown();
			b = $(a).attr('numb');
			$('#multi .title .forground .count .numb').html(b);
		}
    });

//function to get random number from 1 to n
/*function randomToN(maxVal,floatVal)
{
   var randVal = Math.random()*maxVal;
   return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}*/
	firstitem = $('.chartayi .grayframe .tabs').attr('active_tab'); 
	$('.chartayi .grayframe .tabs .tab[numb="'+ firstitem +'"]').addClass('active');
	$('.chartayi .grayframe .curve-box #char-slider ul.char-ul li.char-cont[numb="' + firstitem + '"]').addClass('active');
	height = $('.chartayi .grayframe .curve-box #char-slider ul.char-ul li.char-cont[numb="' + firstitem + '"]').height();
	
	$('.chartayi .grayframe .curve-box #char-slider ul.char-ul li.char-cont').hide(function() {
		$('.chartayi .grayframe .curve-box').animate({'height': height}, 1500, function() {
			$('.chartayi .grayframe .curve-box #char-slider ul.char-ul li.char-cont.active').fadeIn();
		});
	});
	
	$('.chartayi .grayframe .tabs .tab').click( function() {
		if( !$(this).hasClass('active') ) {
			active = $('.chartayi .grayframe .tabs .tab.active').attr('numb');
			$('.chartayi .grayframe .tabs .tab.active').removeClass('active');
			$('.chartayi .grayframe .curve-box #char-slider ul.char-ul li.char-cont.active').removeClass('active');
			
			passive = $(this).attr('numb');
			$('.chartayi .grayframe .tabs .tab[numb="'+ passive +'"]').addClass('active');
			$('.chartayi .grayframe .curve-box #char-slider ul.char-ul li.char-cont[numb="' + passive + '"]').addClass('active');
			height = $('.chartayi .grayframe .curve-box #char-slider ul.char-ul li.char-cont[numb="' + passive + '"]').height();
			$('.chartayi .grayframe .curve-box #char-slider ul.char-ul li.char-cont[numb="' + active + '"]').fadeOut();
			
			$('.chartayi .grayframe .curve-box').animate({'height': height}, 1500, function() {
				$('.chartayi .grayframe .curve-box #char-slider ul.char-ul li.char-cont[numb="' + passive + '"]').fadeIn();
			});
		}
	});
	
	$('.tab-news .curve-box .tab-box').hide();
	$('.tab-news .curve-box .tab-box:first').show();
	$('.tab-news .tabs .tab:first').addClass('active');
	
	$('.tab-news .tabs .tab').click( function() {
		if( !$(this).hasClass('active') ) {
			active = $('.tab-news .tabs .tab.active').attr('numb');
			$('.tab-news .tabs .tab.active').removeClass('active');
			passive = $(this).attr('numb');
			$('.tab-news .tabs .tab[numb="'+ passive +'"]').addClass('active');
			
			height = $('.tab-news .curve-box .tab-box[numb="' + passive + '"]').height();
			$('.tab-news .curve-box .tab-box[numb="' + active + '"]').fadeOut();
			$('.tab-news .curve-box').animate({'height': height}, 1500, function() {
				$('.tab-news .curve-box .tab-box[numb="' + passive + '"]').fadeIn();
			});
		}
	});
	
	$('#patents .tab-box ul li.content').hide(function() {
		passive = $('#patents .tabs .tab:first').attr('numb');			
		$('#patents .tabs .tab:first').addClass('active');
		
		height = $('#patents .tab-box ul li.content[numb="' + passive + '"]').height();
		$('#patents .tab-box').animate({'height': height}, 1500, function() {
			$('#patents .tab-box ul li.content[numb="' + passive + '"]').fadeIn();
		});													   
	});
	
	$('#patents .tabs .tab').click( function() {
		if( !$(this).hasClass('active') ) {
			active = $('#patents .tabs .tab.active').attr('numb');
			$('#patents .tabs .tab.active').removeClass('active');
			passive = $(this).attr('numb');			
			$('#patents .tabs .tab[numb="'+ passive +'"]').addClass('active');
			
			height = $('#patents .tab-box ul li.content[numb="' + passive + '"]').height();
			$('#patents .tab-box ul li.content[numb="' + active + '"]').fadeOut();
			$('#patents .tab-box').animate({'height': height}, 1500, function() {
				$('#patents .tab-box ul li.content[numb="' + passive + '"]').fadeIn();
			});
		}
	});
	
	$('.cat-news .up .archive .rss').mouseover(function() {
		$(this).animate({'margin-top': '0px', 'height': '22px'} ,100);
	});
	$('.cat-news .up .archive .rss').mouseout(function() {
		$(this).animate({'margin-top': '5px', 'height': '17px'} ,100);
	});
	
	$('.newcomment').click(function () {
		x = $('#newcomment').offset().top - 40 ;
     	$('html,body').animate({scrollTop: x },'slow');
	});
	
	$('.comment-link').click(function () {
		x = $('#comments').offset().top - 40;
     	$('html,body').animate({scrollTop: x},'slow');
	});
});

