/*	Author : Cvetozar Ninov */
var carousel_index = 0;
var t = 0;
jQuery(document).ready(function() {
	
	if(jQuery.browser.safari) {
		$(".application .banner.top").css("height","99px");
	}
	
	$('embed').each(function(){
		this.setAttribute('wmode','transparent');
	});
	
	
	var $h = $('.transparent_info').height();
	
	$('#transparent_controll').bind('click',function(){
		$(this).toggleClass('toggle');
		if($(this).hasClass('toggle')) {
			$(this).parent().animate({height: '4px',paddingTop: '4px',paddingBottom: '0px'},500);
		}
		else {
			$(this).parent().animate({height: $h, paddingTop: '10px',paddingBottom: '10px'},500);
		}
	});
		
	$('#home_tabs h2').bind('click',function(){
		ind = $('#home_tabs h2').index(this);
		$('#home_tabs h2.active').removeClass('active');
		$(this).addClass('active');
		$('.comment-accent , .forum-accent').hide();
		$('.'+this.getAttribute('for')).show();
	})
	
	$('#flash_messages').each(function(){
		$(this).css('display', 'none');
		$(this).css('opacity', 0.8);
		$(this).fadeIn('slow');
		$('.close', $(this)).click(function(){ $('#flash_messages').fadeOut(function(){ $(this).remove(); }); });
	});
	
	setTimeout(function(){
		$('#flash_messages').fadeOut(function(){ $(this).remove(); });
		},4000);
		

	$('.footer_logos img').bind("mouseenter",function(){
     $(this).attr("src",$(this).attr("src").replace(".jpg","_over.jpg"));
    }).bind("mouseleave",function(){
      $(this).attr("src",$(this).attr("src").replace("_over.jpg",".jpg"));
    });
    
    
    $(".head_accent ul li a").bind("mouseenter",function(){
    	$('.bigimage').attr("src",$('img',this).attr("src").replace("135x105","378x250"));
    	$('.head_accent h1 a').attr("href",$(this).attr("href")).html($(this).attr("title"));
    	$(".head_accent span").html($(this).attr("class"));
    	$(".head_accent p").html($(this).attr("rel"));
    	$(".head_accent ul li.selected").removeClass("selected");
		$(this).parent().addClass("selected");
		carousel_index = $(".head_accent ul li a").index(this);
    });
    
    $(".head_accent img.bigimage").bind("click",function(){
    	gotourl = $(".head_accent ul li.selected a").attr("href");
    	window.location.href = gotourl;
    })
    
    $(".head_accent").bind("mouseenter",function(){
      clearTimeout(t);
      t = 0;
    }).bind("mouseleave",function(){
       trigger_mouseenter();
    });
    
    trigger_mouseenter();

});

function trigger_mouseenter(){
	t = setTimeout(function(){
	  if (t==0) return;
	  	 clearTimeout(t);
		carousel_index++;
		if(carousel_index == $(".head_accent ul li a").length) {
			carousel_index=0;
		}
		$(".head_accent ul li a:eq("+carousel_index+")").trigger("mouseenter");
		$(".head_accent").trigger("mouseleave");
		//trigger_mouseenter();
	},8000);
}

function add_flash_message(message)
{
		 $('#flash_messages').remove();
		 var flash_message = $('<div style="display: none;" id="flash_messages"><a class="close" href="javascript:;">Hide</a><ul><li>'+message+'</li></ul></div>');

		 flash_message.appendTo($("#wrapper"));
		 
		$('#flash_messages').css('opacity', 0.7);
		$('#flash_messages').fadeIn('slow');
		$('#flash_messages .close').click(function(){ $('#flash_messages').fadeOut(function(){ $(this).remove(); }); });

}