var api, add_click;

$(document).ready(function() {
	
	// Filter submit
	$('.filter').each(function(){
		var 
		form = $(this).parent(),
		btn = $('input[type="submit"]', form).hide();
		
		$('select', form).each(function(){
			$(this).change(function(){
				btn.click();
			});
		});
	});
	
	// Company view item set collapse
	$('#content .item_set').each(function(){
		
		var 
		set = $(this),
		toggler = $('.grandparent a', set),
		span = $('span', toggler);
		
		toggler.click(function(e){
			e.preventDefault();
			if(span.text() == '-')
			{
				set.addClass('closed');
				span.text('+');
			}
			else
			{
				set.removeClass('closed');
				span.text('-');
			}
		});
	});
	
	$('#menu a.grandparent').each(function() {
		$(this).simpletip({  
			content: '<div class="level1"><div class="box"><div class="text">' + $(this).attr('title') + '</div></div></div>',
			position: [200, '-10'],
			showEffect: 'custom',
			showCustom: function() {
				$(this)
					.css('opacity', 0.9)
					.css('display', 'block')
					.animate({ 'left': '-=10px' }, 'fast');
			}
		});
		
		$(this).attr('title', '');
	});
	
	
	var rollers_content	= new Array();
	$.each($('.scrollable a'), function() {				
		
		var roller_id = $(this).attr('id').substr(7);
		
		$.getJSON(site_url + 'get_json/roller_popup_content/' + roller_id, function(data) { 
		 
			rollers_content[roller_id] = '<p class="first"><img src="' + data.logo_href + '" alt="&nbsp;" align="right" />' + data.company + '</p><p><strong>' + data.title + '</strong><br />' + data.date + '</p><p>' + data.content + '</p>';
			
		});
 
	});

	api = $('.scrollable').scrollable({
		vertical: true,
		circular: true,
		speed: 1000
	}).navigator().autoscroll({
		steps: 1,
		interval: 4000,
		autopause: true,
		autoplay: true,
		api: true
	});
	
	/*
	api.onSeek(function() {
		if( api.getIndex() == (api.getSize()-1) )
		{
			setTimeout(function() { api.begin(200); }, 4000);
		}
	});
	*/
			
	//setTimeout('api.play()', 4000);
	
	
	$('.scrollable a, .nonscrollable a').tooltip({
		position: 'center left',
		offset: [0, -20],
		opacity: .9,
		tipClass: 'roller_tooltip radius',
		onBeforeShow: function() {
			var roller_id = this.getTrigger().attr('id').substr(7);
			this.getTip().html( rollers_content[ roller_id ] );
		},
		onShow: function() {
			this.getTip().animate({ 'left': '+=10' }, 'fast');
		}
	});

	
	
	$('.items .item .place, .items .item .date').mouseenter(function() { $(this).parent().children('.place, .date').css('color', 'inherit'); });
	$('.items .item .place, .items .item .date').mouseleave(function() { $(this).parent().children('.place, .date').css('color', '#999'); });
	$('.items .header .place, .items .header .date').unbind('mouseenter').unbind('mouseleave');

	$('.items .item .more').click(function() {

		$('.items .item .more').removeClass('hidden');
		$('.items .item .mored').addClass('hidden');
	
		$(this)
			.parent()
			.parent()
			.find('.more')
			.addClass('hidden')
			.siblings()
			.removeClass('hidden');
	
	}).mouseenter(function() { 
	
		$(this).addClass('hover'); 
		
	}).mouseleave(function() { 
	
		$(this).removeClass('hover'); 
		
	});



	add_click = function(type, key)
	{
		if(type != '' || key > 0)
		{
			$.ajax({
				async: false,
				type: 'POST',
				url: site_url + 'methods/click',
				data: 'type=' + type + '&key=' + key
			});
		}
	}

});


