$(window).load(function() {
	//initialize tooltips
	initTooltips();
	
	//initialize the logo-fader
	$('#banken_logos').cycle();
	
	//initialize the tabs
	$("ul.tabs").tabs("div.panes > div");
	
	//display tweets
	$("#query").tweet({
		join_text: "auto",
		username: "zieltrafficag",
		count: 10
	});
	
	initProductLoader();
	
	$(".button_newsletter_anmelden").colorbox({
		width:"470",
		height:"380",
		iframe:true
	});
	
	$(".button_teilnehmen").colorbox({
		width:"470",
		height:"380",
		iframe:true
	});
});




/**
 * 
 */
function initTooltips() {

    $("#produkte a[title]").tooltip({
        tip: '#tooltip',
        offset: [0, 57],
        effect: 'slide'
    }).dynamic({
        bottom: {
            direction: 'down',
            bounce: false
        }
    });
}

/**
 *
 */
function initProductLoader()
{
	$('#produkte a').click(function(){
		var node_id = this.rel;
		
		//check if we have a valid int here
		if (Math.floor(node_id).toString() == node_id.toString())
		{
			$('#top_overlay').fadeIn();
			$('#ajax_loader').css("display", "block");
		
			var url = "/layout/set/ajax/content/view/embed/"+node_id;
			
			//preload the image
			var img = new Image();
			$(img).load(function(){
				//if image is loaded start the ajax request
				$.get(url, function(data){
					$('#top_content').empty();
					$('#top_content').append(data);
					$('#top_content').css("display", "block");
					
					$('#ajax_loader').css("display", "none");
					$('#top_overlay').fadeOut();
				});
				
			}).attr('src', '/extension/site_geldexperten/design/geldexperten_user/images/header_bilder/bg_'+this.id+'.png');
			




			//there it goes
/*			$.get(url, function(data){
				$('#top_content').empty();
				$('#top_content').append(data);
				$('#top_content').css("display", "block");
				
				$('#ajax_loader').css("display", "none");
				$('#top_overlay').fadeOut();
			});*/
		}
		 
		return false;		
	});
	
	$('#produkte a.prod_geldexperten').click(function(){
		$('#top_content').fadeOut();
	});
}

