/* jTweetsAnywhere settings - enter your username. */
/*---------------------------------------------------------------------*/
var twitter_user_name = 'nemos_';


/* Fancybox settings */
/*---------------------------------------------------------------------*/
function fancybox_settings(){
    jQuery(".single_image, .iframe").fancybox({
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'easingIn'      : 'easeOutBack',
        'easingOut'     : 'easeInBack',
        'speedIn'		: 300, 
        'speedOut'		: 200,
        'titlePosition'	: 'inside',
        'overlayShow'	: true,
        'overlayColor'	: '#000',
        'overlayOpacity': 0.2
    });
}


/* Cufon Font replacement */
/*---------------------------------------------------------------------*/
Cufon.replace('#bottom_header, #top_footer p', {
    fontFamily: "Helsinki",
    textShadow:"0px 1px 1px rgba(0,0,0,0.5)"
});
Cufon.replace('#slogan', {
    fontFamily: "Bebas Neue",
});


/* Regular expression to validate email address */
/*---------------------------------------------------------------------*/
function validateEmail(emailValue){  
	var emailPattern = /^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	return emailPattern.test(emailValue); 
}


/* Validate Form fields */
/*---------------------------------------------------------------------*/
function validateForm(){
	var fields_valid = true;
    
    if (jQuery("input#name").val().length < 2) {
		jQuery("label#name_error").fadeIn('slow');
		jQuery("input#name").focus();
		fields_valid = false;
	}
	if (!validateEmail(jQuery("input#email").val())) {
		jQuery("label#email_error").fadeIn('slow');
		if(fields_valid) jQuery("input#email").focus();
		fields_valid = false;
    }
	return fields_valid;
}


jQuery(function(){

    fancybox_settings();
    
    
    /* Screenshots Carousel */
    /*---------------------------------------------------------------------*/
    var carousel_length = jQuery(".carousel ul").children().length * 3000;
    jQuery(".carousel ul").css('width', carousel_length);
    
    jQuery(".carousel").hover(
        function () {
            jQuery(".carousel_btn_left").not(':animated').show();
            jQuery(".carousel_btn_right").not(':animated').show();
        }, 
        function () {
            jQuery(".carousel_btn_left").not(':animated').hide();
            jQuery(".carousel_btn_right").not(':animated').hide();
        }
    );
    
    jQuery(".carousel_btn_left").click(function(){
        var ul_position = jQuery(".carousel ul").position();
        
        if(ul_position.left < 0){
            jQuery(".carousel ul").not(':animated').animate({ left: '+=215' }, {
                            duration: 'slow',
                            easing: 'easeOutExpo'});
        }
        return false;
    });
    
    jQuery(".carousel_btn_right").click(function(){
        var ul_position = jQuery(".carousel ul").position();
        var ul_width = jQuery(".carousel ul").width();
        var count_position = ul_width - (-ul_position.left) - 870;
        
        if(count_position > 0){
            jQuery(".carousel ul").not(':animated').animate({ left: '-=215' }, {
                            duration: 'slow',
                            easing: 'easeOutExpo'});
        }
        return false;
    });
    
    

    

    
    
    
    
    /* Avatar Tip */
    /*---------------------------------------------------------------------*/
    jQuery('.tip_trigger').each(function() {        
        var tip = jQuery(this).find('.avatar_tip');

        jQuery(this).hover(
            function() { tip.not(':animated').fadeIn(); },
            function() { tip.hide(); }
        ).mousemove(function(e) {
            var avatar_x = e.pageX + 15,
                avatar_y = e.pageY + 15,
                avatar_width = tip.width(),
                avatar_height = tip.height(),
                distance_x = jQuery(window).width() - (avatar_x + avatar_width),
                distance_y = jQuery(window).height() - (avatar_y + avatar_height);

            if ( distance_x < 15 ) avatar_x = e.pageX - avatar_width - 15;
            if ( distance_y < 15 ) avatar_y = e.pageY - avatar_height - 15;

            tip.css({ left: avatar_x, top: avatar_y });
        });         
    });
})
