var count = 2;
var scroll_duration = -3000;


$(document).ready(function () 
{
	$(".slider_trigger").click(function () {
        
        if (!$(this).parent().hasClass('selected'))
        {
            $(".slider_trigger").parent().removeClass('selected');
            $(this).parent().addClass('selected');
		
        
            count = parseInt($(this).attr('href').replace('#', ''));
            element = $("#slider_"+count);
        
            document.cookie="prev="+count+"; path=/; expires=Mon, 01-Jan-2100 00:00:00 GMT";
            
            element.hide();
            
            $('#slider_contenner').append(element);
            
            element.fadeIn(1000)
            scroll_duration = 0;
            
            
        }	
		return false;
	});
    
    slide();
	
	$(".menu_mover_hov").click(function () {
		return false;
	});
	
	$(".menu_mover").click(function () {
		return false;
	});


	$('.buttom_classic').mouseover(function(){
		if ($(this).attr('block') != 'yes')
		{
			$(this).find('.bt_left').css('background-position', '0px -26px');
			$(this).find('.bt_right').css('background-position', '0px -26px');
			$(this).find('.bt_middle').css('background-position', '0px -26px');
		}
	});
		
	$('.buttom_classic').mouseout(function(){
		if ($(this).attr('block') != 'yes')
		{
			$(this).find('.bt_left').css('background-position', '0px 0px');
			$(this).find('.bt_right').css('background-position', '0px 0px');
			$(this).find('.bt_middle').css('background-position', '0px 0px');
		}
	});
 
	$('.buttom_classic').mousedown(function(){
		if ($(this).attr('block') != 'yes')
		{
			$(this).find('.bt_left').css('background-position', '0px -52px');
			$(this).find('.bt_right').css('background-position', '0px -52px');
			$(this).find('.bt_middle').css('background-position', '0px -52px');
		}
	});
	
	$('.buttom_classic').mouseup(function(){
		if ($(this).attr('block') != 'yes')
		{
			$(this).find('.bt_left').css('background-position', '0px -26px');
			$(this).find('.bt_right').css('background-position', '0px -26px');
			$(this).find('.bt_middle').css('background-position', '0px -26px');
		}
	});
	
	$('.buttom_classic').click(function() {
		if ($(this).attr('block') != 'yes')
		{
			$('#'+$(this).attr('toclick')).click();			
		}
	});
	
	
	$('.buttom_classic').each(function() {
	
		if ($(this).attr('block') == 'yes')
		{
			$(this).find('.bt_left').css('background-position', '0px -78px');
			$(this).find('.bt_right').css('background-position', '0px -78px');
			$(this).find('.bt_middle').css('background-position', '0px -78px');
		}
	});    
    
    $('#menu ul li').mouseover(function () {
        if ($(this).attr('id') != 'cue_h_men')
        {
            $(this).addClass('selected');
        }
       
    });
    
    
    $('#menu ul li').mouseout(function(){
        if ($(this).attr('id') != 'cue_h_men')
        {
            $(this).removeClass('selected');
        }
    });
    
    $('#menu ul li').click( function() {
        location.href = $(this).find('a').attr('href');
    });
    
    $('.plinc').change( function() {
        cs = $(this).find('option:selected').val();
    
        $('#blc1, #blc2, #blc3, #blc4, #blc5').hide();
        
        switch (cs)
        {
            case '5':
                $('#blc5').show();
            case '4':
                $('#blc4').show();
            case '3':
                $('#blc3').show();
            case '2':
                $('#blc2').show();
            case '1':
                $('#blc1').show();
        }
    });
    
    $('.siding').click( function() {
        $('.preside').fadeOut();
        
        $('#di_'+$(this).val()).fadeIn();
    });
    
    
    $('.multitabs li').click( function () {
        $('.multitabs li').removeClass('selected');
        $(this).addClass('selected');
        
        $('.alltabs').hide();
        $('#tab_'+$(this).attr('id')).show();
    });
    
    $('#feedsend').click( function () {
        err = 0;
        if ($('#imp_name').val().length < 1)
        {
            $('#feed_name').fadeIn();
            err = 1;
        }
        if ($('#imp_comp').val().length < 1)
        {
            $('#feed_comp').fadeIn();
            err = 1;
        }
        if (!testEmail($('#imp_email').val()))
        {
            $('#feed_email').fadeIn();
            err = 1;
        }
        if ($('#imp_text').val().length < 1)
        {
            $('#feed_text').fadeIn();
            err = 1;
        }
        if (err)
        {
            return false;
        }
        else
        {
            return true;
        }
        
    }); 
    
    
     $('#contsend').click( function () {
        err = 0;
        if ($('#imp_name').val().length < 1)
        {
            $('#feed_name').fadeIn();
            err = 1;
        }
        if ($('#imp_phone').val().length < 1)
        {
            $('#feed_phone').fadeIn();
            err = 1;
        }
        if (!testEmail($('#imp_email').val()))
        {
            $('#feed_email').fadeIn();
            err = 1;
        }
        if ($('#imp_text').val().length < 1)
        {
            $('#feed_text').fadeIn();
            err = 1;
        }
        if (err)
        {
            return false;
        }
        else
        {
            return true;
        }
        
    }); 
    
    $('#imp_name').click(function () {
        $('#feed_name').fadeOut();
    });
    $('#imp_comp').click(function () {
        $('#feed_comp').fadeOut();
    });
    $('#imp_email').click(function () {
        $('#feed_email').fadeOut();
    });
    $('#imp_text').click(function () {
        $('#feed_text').fadeOut();
    });
    $('#imp_phone').click(function () {
        $('#feed_phone').fadeOut();
    });
    
    
    $('#calen').click(function () {

        $('#example').focus()
        return false;
    });
    
});


function delta(progress) 
{
    return Math.pow(progress, 2);
}


/* else functions */
function testEmail(email)
{
	if (email == ''){
		return false;
	}

	var idx = email.indexOf('@');

	if (idx > 0){

		var point = false;
		var st = 0;
		var ed = idx;
		var ch = 0;

		for(j = 0; j < 2; j++){
			next = false;
			error = false;

			for(i = st; i < ed; i++){

				ch = email.charCodeAt(i);

				if ((ch == 46)||(ch == 45)||(ch == 95)){
					if (!next){
						error = true;
						break;
					}
					next = false;
					if ((j == 1)&&(ch == 46)){
						point = true;
					} else {
						point = false;
					}
				} else {
					if (((ch >= 48)&&(ch <= 57))||
						((ch >= 97)&&(ch <= 122))||
						((ch >= 65)&&(ch <= 90))){
						next = true;
					} else {
						error = true;
						break;
					}
				}
			}

			if ((!error)&&(!next)){
				error = true;
			}

			if (error){
				break;
			}

			st = idx + 1;
			ed = email.length;
		}

		if ((error)||(!point)){
			return false;
		} else {
			return true;
		}

	} else {
		return false;
	}

}


    function slide()
    {
        
        setTimeout(function() 
        {
            
            if (scroll_duration >= 3000)
            {
                if (count == 5)
                {
                    count = 1;
                }
                $('.slider_trigger[href="#'+count+'"]').click();
                count++;
                
                scroll_duration = 0;
            }
            else
            {
                scroll_duration += 10;
            }
            slide();
        }, 10);
    }
