$(document).ready(function() {
    
    $('a.external').attr('target', '_blank');
    
    $('#navMain > ul').fadingnav({ fadeSpeed: 650, initialPos: '0 0', hoverPos: '0 -50px' });
    
    $('select.replaceable').selectreplace();
    
    if ($('.contactForm div.delete-upload').length > 0) {
        $('.contactForm div.delete-upload').find('.delete-upload').click(function(e) {
            var parent = $(this).parent();
            var input = $(this).siblings('input[type=hidden]').clone();
            var inputName = input.attr('id').replace(/uploaded/, 'upload');
            input.val('').attr({
                'type': 'file',
                'name': inputName
            }).removeAttr('id').removeAttr('value');
            parent.replaceWith(input);
            e.preventDefault();
            return false;
        })
    }
    
    var opts = {
        duration: 500,
        fadeDuration: 250,
        minWidth: 148,
        maxWidth: 308,
        tout: null
    }
    
    _over = function(e) {
            window.clearTimeout(opts.tout);
            opts.tout = null;

            if ($(this).hasClass('active'))
                return false;
            
            $(this).siblings(':animated, .active').each(function() {
                $(this).stop().animate({
                    width: opts.minWidth
                }, {
                    duration: opts.duration
                });
                $(this).find('a').stop().animate({ opacity: 0 }, {
                    duration: opts.fadeDuration,
                    complete: function(){
                        $(this).parent('li').removeClass('active');
                        $(this).animate({ opacity: 1 }, opts.fadeDuration);
                    }
                });
            });
            
            $(this).stop().animate({
                width: opts.maxWidth
            }, {
                duration: opts.duration
            });
            $(this).find('a').stop().animate({ opacity: 0 }, {
                    duration: opts.fadeDuration,
                    complete: function(){
                        $(this).parent('li').addClass('active');
                        $(this).animate({ opacity: 1 }, opts.fadeDuration);
                    }
                });
        }
    
    $('.welcomeCon ul li').hover(
        _over,
        function() {
            opts.tout = window.setTimeout(function() {
                $('.welcomeCon ul li:first').trigger('mouseover');
            }, 250)
        }
    );
	
	// tooltips
	var toolTipContainer = $('<div class="tooltip"><div class="close"></div><div class="main"></div></div>');
	$('body').append(toolTipContainer)
	toolTipContainer.find('.close').click(function(){toolTipContainer.hide(0)})
	$('.toolTipC').hover(function(e){
			var _l = $(this).position().left + 10;
			var _t = $(this).position().top + 120;
			toolTipContainer.css({
				left: _l,
				top: _t
			}) 
			toolTipContainer.find('.main').html($(this).siblings('.toolTipContent').html());
			if($(this).hasClass('sticky')) 
				toolTipContainer.find('.close').show(0);
			else
				toolTipContainer.find('.close').hide(0);
			toolTipContainer.show(0);
	}, function(e) {
		if(!$(this).hasClass('sticky'))
		toolTipContainer.hide(0);
		/*if($(this).hasClass('sticky') && $('#fragment-1 ,#fragment-2, #fragment-3, #fragment-4').click()) {
			toolTipContainer.hide(0);
		}*/
	}).mousemove(function(e) { 
        toolTipContainer.css({
			left: e.pageX + 15
		}) 
    });
	
	
	$('.dateChecker input[type="text"]').focus(function() {
		if($(this).attr('title') == $(this).val())
			$(this).val('');
	}).blur(function() {
		if('' == $(this).val())
			$(this).val($(this).attr('title'));
	});
    
})
