// HEADER animation
var headerHeightMax = "260px"; 
var headerHeightMin = "15px"; 
var headerHeight = headerHeightMax; 
var header_i = '60';	    


// paramater Z index
var zindex_default = 20;
var zindex_current = 0;

////////////////////////
// scrolling tree
var treeCurrentDrap = '';
var postionScrollCurrent = 0;
var arrayObjectTreeLeft = new Array();
var arrayObjectTreeTop = new Array();
var arrayObjectTreeIndex = new Array();
var arrayObjectTreeMain = new Array("temperature", "weather", "video", "calendar", "facebookfeeds", "clock", "twitter", "airquality", "rainrate", "lowimpact", "soundcloud", "picture", "facebook", "windspeedbox", "group_tree");
var lenArrayTree=arrayObjectTreeMain.length;


//temperature
arrayObjectTreeLeft[arrayObjectTreeMain[0]] = '54';
arrayObjectTreeTop[arrayObjectTreeMain[0]] = '213';
arrayObjectTreeIndex[arrayObjectTreeMain[0]] = 5;

//weather
arrayObjectTreeLeft[arrayObjectTreeMain[1]] = '118';
arrayObjectTreeTop[arrayObjectTreeMain[1]] = '133';
arrayObjectTreeIndex[arrayObjectTreeMain[1]] = 4;

//video
arrayObjectTreeLeft[arrayObjectTreeMain[2]] = '220';
arrayObjectTreeTop[arrayObjectTreeMain[2]] = '30';
arrayObjectTreeIndex[arrayObjectTreeMain[2]] = 2;

//calendar
arrayObjectTreeLeft[arrayObjectTreeMain[3]] = '555';
arrayObjectTreeTop[arrayObjectTreeMain[3]] = '192';
arrayObjectTreeIndex[arrayObjectTreeMain[3]] = 3;

//facebookfeeds
arrayObjectTreeLeft[arrayObjectTreeMain[4]] = '0';
arrayObjectTreeTop[arrayObjectTreeMain[4]] = '340';
arrayObjectTreeIndex[arrayObjectTreeMain[4]] = 8;

//clock
arrayObjectTreeLeft[arrayObjectTreeMain[5]] = '690';
arrayObjectTreeTop[arrayObjectTreeMain[5]] = '150';
arrayObjectTreeIndex[arrayObjectTreeMain[5]] = 1;

//twitter
arrayObjectTreeLeft[arrayObjectTreeMain[6]] = '770';
arrayObjectTreeTop[arrayObjectTreeMain[6]] = '560';
arrayObjectTreeIndex[arrayObjectTreeMain[6]] = 9;

//airquality
arrayObjectTreeLeft[arrayObjectTreeMain[7]] = '853';
arrayObjectTreeTop[arrayObjectTreeMain[7]] = '364';
arrayObjectTreeIndex[arrayObjectTreeMain[7]] = 2;

//rainrate
arrayObjectTreeLeft[arrayObjectTreeMain[8]] = '17';
arrayObjectTreeTop[arrayObjectTreeMain[8]] = '760';
arrayObjectTreeIndex[arrayObjectTreeMain[8]] = 8;

//lowimpact
arrayObjectTreeLeft[arrayObjectTreeMain[9]] = '69';
arrayObjectTreeTop[arrayObjectTreeMain[9]] = '860';
arrayObjectTreeIndex[arrayObjectTreeMain[9]] = 4;

//soundcloud
arrayObjectTreeLeft[arrayObjectTreeMain[10]] = '173';
arrayObjectTreeTop[arrayObjectTreeMain[10]] = '830';
arrayObjectTreeIndex[arrayObjectTreeMain[10]] = 5;

//picture
arrayObjectTreeLeft[arrayObjectTreeMain[11]] = '432';
arrayObjectTreeTop[arrayObjectTreeMain[11]] = '815';
arrayObjectTreeIndex[arrayObjectTreeMain[11]] = 3;

//facebook
arrayObjectTreeLeft[arrayObjectTreeMain[12]] = '61';
arrayObjectTreeTop[arrayObjectTreeMain[12]] = '620';
arrayObjectTreeIndex[arrayObjectTreeMain[12]] = 7;

//windspeedbox
arrayObjectTreeLeft[arrayObjectTreeMain[13]] = '867';
arrayObjectTreeTop[arrayObjectTreeMain[13]] = '228';
arrayObjectTreeIndex[arrayObjectTreeMain[13]] = 3;

//group_tree
arrayObjectTreeLeft[arrayObjectTreeMain[14]] = '310';
arrayObjectTreeTop[arrayObjectTreeMain[14]] = '635';
arrayObjectTreeIndex[arrayObjectTreeMain[14]] = 15;






var arrayDefaultObjectTreeLeft = new Array();
var arrayDefaultObjectTreeTop = new Array();

//temperature
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[0]] = '54';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[0]] = '213';

//weather
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[1]] = '118';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[1]] = '133';

//video
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[2]] = '220';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[2]] = '30';

//calendar
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[3]] = '555';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[3]] = '192';

//facebookfeeds
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[4]] = '0';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[4]] = '340';

//clock
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[5]] = '690';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[5]] = '150';

//twitter
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[6]] = '770';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[6]] = '560';

//airquality
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[7]] = '853';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[7]] = '364';

//rainrate
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[8]] = '17';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[8]] = '760';

//lowimpact
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[9]] = '69';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[9]] = '860';

//soundcloud
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[10]] = '173';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[10]] = '830';

//picture
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[11]] = '432';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[11]] = '815';

//facebook
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[12]] = '61';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[12]] = '620';

//windspeedbox
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[13]] = '867';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[13]] = '228';

//group_tree
arrayDefaultObjectTreeLeft[arrayObjectTreeMain[14]] = '310';
arrayDefaultObjectTreeTop[arrayObjectTreeMain[14]] = '635';

// end scrolling tree
////////////////////////
$(window).load(function(){
	$("#loadingpage").hide();
	$("#screenfixed").css('left','0');
	$("#divCenterScroll, .bg_transparent").show();
});



$(document).ready(function(){
	var isHeaderRunning = false;
	
	initZindexTree();
	hovericon();
	clickTreeObject();
	///////////////////////////////////////////
	// Header
	//moving header 
	var staticHeader = false ;

	$('#header').mouseover(function() {
		if(!staticHeader)
		{
			$("#header_about").hide();	
			staticHeader = true;
			$("#header").stop(true,false).animate({"top": "0"}, 800, 'easeOutBounce', function(){
				add_google_tracker('Popup Hello clicked','onclick','');	
			});			
		}
	}).mouseleave(function() {
		
		if(staticHeader)
		{	
			staticHeader = false;
			$("#header_about").show();
			$("#header").stop(true,false).animate({"top": "-225px"}, 800, 'easeOutBounce', function(){
				
			});			
		}	
	});
		
	// End Header
	///////////////////////////////////////////
	
	//////////////////////////////////////////
	// Share This
	$("#shareThisFB").hover(
		function () {
			$('.shareme').css({'left':'203px','top':'64px'});
			$('.shareme').stop(true,true).fadeIn(500);	
		},
		function () {
			$('.shareme').stop(true,true).fadeOut('fast');	
		}
	);

	$("#shareThisTweeter").hover(
		function () {
		$('.shareme').css({'left':'232px','top':'64px'});
			$('.shareme').stop(true,true).fadeIn(500);	
		},
		function () {
			$('.shareme').stop(true,true).fadeOut('fast');	
		}
	);	

	// End Share This
	//////////////////////////////////////////
	
	
	//////////////////////////////////////////
	// Draggable box
	//  when you go over a box, it should be come top layer
	var staticDraggableMouseOutSide = 0;
	$('.draggable').mouseenter(function() {
		initZindexTree();
		zindex_current = $(this).css('z-index');
		$(this).css('z-index',zindex_default);
		staticDraggableMouseOutSide = 1;
	}).mouseleave(function() {
		//$(this).css('z-index',zindex_current);
		staticDraggableMouseOutSide = 0;
	});
	
	////////////////////////////////////////////
	//stop draggabel to scroll in the radio list (soundclound)
	$('.flash').hover(function(){
		$('.draggable').draggable( "disable" )
	},function(){
		$('.draggable').draggable( "enable" )
	});//end function
	
	$(document).click(function(event) { 
		if(staticDraggableMouseOutSide == 0){
			initZindexTree();
		}
	});
	
	// draggable
	var objDrap = '';
	if($.browser.msie && $.browser.version == 7)
		objDrap = 'html';
	else	
		objDrap = 'body';
		
	$('.draggable').draggable({ 
		containment: objDrap,
		scroll: true ,
		drag: function(event, ui) { 
			if( ($(window).height() - 100) <= ui.position.top){
				//$(window).scrollTop($(window).scrollTop() + 100);
				treeCurrentDrap = $(this).attr('bliss');
			}
		},
		stop: function(event, ui) { 
			//alert( $(window).height() + ' ' + ui.position.top );
			var objName = $(this).attr('bliss');
			arrayObjectTreeLeft[objName] = ui.position.left;
			arrayObjectTreeTop[objName] = ui.position.top + postionScrollCurrent;
		}
	});
	
	// end Draggable box
	//////////////////////////////////////////
			
	//reset-root
	$("#reset-root").click(function(){		
		resetPositionTree();
	});
	// End move box
	//////////////////////////////////////////	
	$(function(){
		$('.go_button').hover(function(){
			$(this).css({'opacity':'0.8'});
		}, function(){
			$(this).css({'opacity':'1'});
		});
	});

	
	//////////////////////////////////////////	
	// Scrolling
	$(window).scroll(function() {
		//alert($(window).scrollTop());		
		followTreePosition($(window).scrollTop());
	});
	// Scrolling
	//////////////////////////////////////////	
	
	$('#panel_facebookfeeds').jScrollPane({showArrows:true, scrollbarWidth: 6});
	$('#panel_twitter').jScrollPane({showArrows:true, scrollbarWidth: 6});
	
});	
// end HEADER animation


function closeWelcome(){
	$('.bg_transparent').hide();
	$('.popup_welcome').hide();
	$(window).scrollTop(240);
} // end function

/* ---------------------------- */
/* Scrolling */
function initZindexTree(){
	for(var i=0; i<lenArrayTree; i++) {
		objTree = arrayObjectTreeMain[i];
		$('.' + objTree).css('z-index',arrayObjectTreeIndex[objTree]);
	}	
}//end function

function resetPositionTree(){
	
	for(var i=0; i<lenArrayTree; i++) {
		objTree = arrayObjectTreeMain[i];
		newTop = parseInt( arrayDefaultObjectTreeTop[objTree] );
		
		$('.' + objTree).stop(true,true).animate({left: arrayDefaultObjectTreeLeft[objTree] + 'px', top: newTop + 'px'}, 1500, function(){
			$(window).scrollTop(0);
		} );

		arrayObjectTreeLeft[arrayObjectTreeMain[i]] = arrayDefaultObjectTreeLeft[objTree];	
		arrayObjectTreeTop[arrayObjectTreeMain[i]] = newTop;		
		// move to top
		
		
	}
}
function followTreePosition(valueScroll){
	var newTop = 0;
	//alert(treeCurrentDrap);
	postionScrollCurrent = valueScroll;
	for(var i=0; i<lenArrayTree; i++) {
		objTree = arrayObjectTreeMain[i];
		newTop = parseInt( arrayObjectTreeTop[objTree] ) - valueScroll;
		$('.' + objTree).stop(true,false).animate({left: arrayObjectTreeLeft[objTree] + 'px', top: newTop  + 'px'}, randowTime() );
	}
}

function randowTime(){
	var rand_no = Math.random();
	rand_no = parseInt( 300 + rand_no * 500 );
	return rand_no;
}
/* End Scrolling */
/* ---------------------------- */

function hovericon(){
	$('.icon_fb img').hover(function(){
		$(this).animate({'opacity':'0'},300);
	},function(){
		$(this).animate({'opacity':'1'},300);
	});
	
	$('.icon_tw img').hover(function(){
		$(this).animate({'opacity':'0'},300);
	},function(){
		$(this).animate({'opacity':'1'},300);
	});
	
	$('img.germany_flag').hover(function(){
		$('.shareme2').animate({'opacity':'1'},300);
	},function(){
		$('.shareme2').animate({'opacity':'0'},300);
	});
	
	$('.close img').hover(function(){
		$(this).animate({'opacity':'0.5'},300);
	},function(){
		$(this).animate({'opacity':'1'},300);
	});
}

////////////////////////////////
// Open popup
function add_google_tracker(category,action,label)
{
	_gaq.push(['_trackEvent',category, action, label]);
}
function clickTreeObject(){
	$(".addme").click(function(){	
		add_google_tracker('AddMeToYourBlog clicked','onclick','');
		openDivPopup('#popup_addweb');
	});	
	
	$(".airquality").click(function(){	
		add_google_tracker('Air Quality clicked','onclick','');	
		openDivPopup('.popup_airquality');
	});	
	
	$(".lowimpact").click(function(){
		add_google_tracker('Low Impact clicked','onclick','');			
		openDivPopup('#popup_impact');
	});	
	
	$(".weather").click(function(){	
		add_google_tracker('Weather clicked','onclick','');	
		openDivPopup('#popup_weather');
	});	

	$(".rainrate").click(function(){
		add_google_tracker('Rain clicked','onclick','');		
		openDivPopup('#popup_rain');
	});

	$("object").click(function(){		
		CopyToClipboard();
	});			
}// end function

function openDivPopup(ojb){
	$(ojb).show();
	$(".bg_transparent").show();	
}

function closeDivPopup(ojb){
	$(ojb).hide();
	$(".bg_transparent").hide();	
}

function openCopyCodePopup(value){
	var txt = '';
	if(value == 1){
		txt = '&lt;a href=&quot;http://www.talking-tree.com/&quot;&gt;&lt;img src=&quot;http://talking-tree.com/blog_image.php?type_widget=large&quot; border=&quot;0&quot;/&gt;&lt;/a&gt;';
		staticCopy = 1;	
		
		$("#clipboard01").show();
		$("#clipboard02").hide();
	}
		
	else{
		txt = '&lt;a href=&quot;http://www.talking-tree.com/&quot;&gt;&lt;img src=&quot;http://talking-tree.com/blog_image.php?type_widget=small&quot; border=&quot;0&quot;/&gt;&lt;/a&gt;';
		staticCopy = 2;	
		$("#clipboard01").hide();
		$("#clipboard02").show();
		$("#clipboard01, #clipboard02").css('cursor','pointer');	
	}
	
		
	$(".bg_transparent").css('z-index','10000');	
	
	$("#copycodetext").html(txt);
	$(".popup_copycode").show();
	
	$(".text_copycode").html('Copy my code');
}

function closeCopyCodePopup(ojb){
	$(".bg_transparent").css('z-index','9998');	
	$(".popup_copycode").hide();
}

// End Open popup
////////////////////////////////
function show_data_callback(component_id,data)
{
	$('#'+component_id).html(data);
}

$(window).load(function(){
	setTimeout('update_facebook()',120000);
	setTimeout('update_twitter()',180000);
	setTimeout('update_fisheye()',40000);
});
function update_facebook()
{
	$.ajax({
		   type: "GET",
		   url: "ajax/facebook_data.php",
		   data: "",
		   success: function(msg){				  
				$('#callback_data_temp_facebook').html(msg);				
				show_data_callback('facebookfeeds',$('#callback_facebook_feeds').html());
				$('#panel_facebookfeeds').jScrollPane({showArrows:true, scrollbarWidth: 6});
				show_data_callback('panel_facebookfriends',$('#callback_facebook_friends').html());				
				$('#callback_data_temp_facebook').html('');	
				setTimeout('update_facebook()',120000);
		   } ,
		   beforeSend: function(msg){
			
		   } ,
		   complete: function(msg){
			  
		   }
		 });
}
function update_twitter()
{
	$.ajax({
		   type: "GET",
		   url: "ajax/twitter_data.php",
		   data: "",
		   success: function(msg){				  
				$('#callback_data_temp_twitter').html(msg);				
				show_data_callback('twitter_feeds',$('#callback_twitter_feeds').html());
				$('#panel_twitter').jScrollPane({showArrows:true, scrollbarWidth: 6});
				show_data_callback('group_tree_date_container',$('#date_first_twiter_posted').html());				
				$('#callback_data_temp_twitter').html('');	
				setTimeout('update_twitter()',180000);
		   } ,
		   beforeSend: function(msg){
			
		   } ,
		   complete: function(msg){
			  
		   }
		 });
}
function update_fisheye()
{
	$.ajax({
		   type: "GET",
		   url: "ajax/fisheye_data.php",
		   data: "",
		   success: function(msg){				  
				$('#callback_data_temp_fisheye').html(msg);				
				show_data_callback('fisheye_airquality',$('#callback_fisheye_airquality').html());
				show_data_callback('fisheye_airquality_popup',$('#callback_fisheye_airquality_popup').html());	
				show_data_callback('fisheye_mood',$('#callback_fisheye_mood').html());	
				show_data_callback('fisheye_rain',$('#callback_fisheye_rain').html());
				show_data_callback('fisheye_rain_popup',$('#callback_fisheye_rain_popup').html());					
				show_data_callback('fisheye_sentence',$('#callback_fisheye_sentence').html());		
				show_data_callback('fisheye_temperature',$('#callback_fisheye_temperature').html());
				show_data_callback('fisheye_weather',$('#callback_fisheye_weather').html());
				show_data_callback('fisheye_weather_popup',$('#callback_fisheye_weather_popup').html());
				show_data_callback('fisheye_windspeed',$('#callback_fisheye_windspeed').html());
				show_data_callback('fisheye_calendar',$('#callback_fisheye_calendar').html());																									
				$('#callback_data_temp_fisheye').html('');
				setTimeout('update_fisheye()',40000);	
		   } ,
		   beforeSend: function(msg){
			
		   } ,
		   complete: function(msg){
			  
		   }
		 });
}






