jQuery(function($){
	 $('.blink').
        focus(function() {
            if(this.title==this.value) {
                this.value = '';
            }
        }).
        blur(function(){
            if(this.value=='') {
                this.value = this.title;
            }
        });
	
	var dd_width = $('.drop-down-btn .dd').parent().width();
	$.each($('.drop-down-btn .dd'), function() {
		$(this).css('width',$(this).parents('.drop-down-btn:eq(0)').width());
	});


	$('.trigger').click(function(){
		var index = $(this).parent().parent().find('.trigger').index(this);
		var other_index = index == 0 ? 1 : 0;
		
		var shell = $('#top-section .shell').eq(index);
		var cont_height = shell.find('.top-section').height();
		var other_shell = $('#top-section .shell').eq(other_index);
		
		other_shell.animate({ 'height': 0 });
		$('.trigger').eq(other_index).removeClass('trigger-active');
		
		
		if( shell.css('height') == cont_height + 'px' ) {
			shell.animate({ 'height': '0px' });
			$(this).removeClass('trigger-active');
		} else {
			shell.animate({ 'height': cont_height + 'px' });
			$(this).addClass('trigger-active');		
		}
		
		return false;
	});
	
	$('.slide-images-nav li:last').addClass('last');

	$('.featured-news-slide ul').each(function() {
		$(this).find('li:last').addClass('last');
	});
	
	$('.featured-news ul:first').show();
	
	$('.slide-images-nav a').slide({
		'slide_selector': '.featured-news-slide ul',
		'auto': true,
		'time': 10000
	});
	
	$('#navigation li').hover(
		function(){
			var dd = $(this).find('.dd:eq(0)');
			
			if(dd.length == 0)
				return;
				
			dd.show();
		
			$(this).find('a:eq(0)').addClass('hover');
		},
		function(){
			var dd = $(this).find('.dd');
			
			if(dd.length == 0)
				return;
				
			dd.hide();
			$(this).find('a:eq(0)').removeClass('hover');
		}
	)
	
	$('.dd li').each(function(){
		if( $(this).find('.dd').length > 0 )
			$(this).find('a:eq(0)').addClass('has-dd');
	});
		
	$('.featured-news .image-holder a').hover(
		function(){ $(this).addClass('hover'); },
		function(){ $(this).removeClass('hover'); }
	);
	
	
	$('.main-image').append('<div id="loader"></div>');
	
	var max_index = headers.length;
	var rand =  Math.floor(Math.random() * (max_index - 0));
	$('.main-image img').attr({ 'src' : headers[rand] });
	$('.main-image img').hide();
	
	var img = new Image();
	$(img).load(function () {
		window.setTimeout(function(){
			$('.main-image img').hide();
			$('#loader').fadeOut(function(){ $('.main-image img').fadeIn(2000) });
			
		}, 10);
		
	}).error(function () {
	
	}).attr('src', headers[rand]);
	
	$('#navigation ul').each(function() {
		$(this).find('>li:last').addClass('last');
	});
	
	$('.inner-sidebar > ul > li:last').addClass('last');
	
	$('a.has-dd').click(function() {
		return false;
	});
	
	$('.lightbox').lightBox({
        imageLoading:           __root + '/images/lightbox-ico-loading.gif',
        imageBtnPrev:           __root + '/images/lightbox-btn-prev.gif',
        imageBtnNext:           __root + '/images/lightbox-btn-next.gif',
        imageBtnClose:          __root + '/images/lightbox-btn-close.gif',
        imageBlank:             __root + '/images/lightbox-blank.gif'
    });
	
});

