/*

Tabs

*/
//required for each plugin

$(function() {

// by default, open FIRST pane 
           var initab = 0;  
               lhash = window.location.hash;  
           // Test for sections with subnavigation
           
           if (lhash == '' ) {
				var initab = 0;
			} else if (lhash.indexOf("read-excerpt") != -1 ) {
				var initab = 2;
			} else if (lhash.indexOf("author") != -1 ) {
				var initab = 3;
			} else if (lhash.indexOf("buzz")  != -1) {
				var initab = 4;
			}
			
			
           // before installing tabs, check whether we open a pane  
           if (lhash) {  
             // try to exctract initial tab index  
             // assuming #t + index  
             lhash = parseInt(lhash.substring(lhash.lastIndexOf("#t") + 2), 10); 
             initab = isNaN(lhash) ? initab : lhash;
                
           }  
           
           var $mainTabs = $('#menu-primary-links ul.menu');
			
$mainTabs.tabs("div.contentWindow", {
		effect: 'fade',
		fadeOutSpeed: 150, 
        fadeInSpeed: 1000, 
        initialIndex: initab,
        
        onBeforeClick: function(event, i) {
			// get the pane to be opened
			var pane = this.getPanes().eq(i);
			pane.html('<p class="loading" ><img src="/drupal/sites/all/themes/thewisdomofbees/images/ajaxLoading.gif"/></p>'); 
						
			// only load once. remove the if ( ... ){ } clause if you want the page to be loaded every time
			//if (pane.is(":empty")) {
				// load it with a page specified in the tab's href attribute
				pane.load(this.getTabs().eq(i).attr("href") + ' .container');
			//}
			
			// Slides white content window up and down			
			if (i==0){
				$("#primaryWindow").addClass("homePanel");
				$('#primaryWindow').animate({'marginTop' : "400px"});

			} else {
				$("#primaryWindow").removeClass("homePanel");
				$('#primaryWindow').animate({'marginTop' : "0px"});
			};	
			
					
		
		},
        
        // functions on pane loading 
         onClick: function(index,i) { 
			var $currentTab = "#contentWindow-"+i;
			var $currentSubnav = $currentTab + " .subnav ul.menu ul.menu";
			pageTracker._trackPageview(window.location.hash);
			//alert (window.location.hash);	
  			if($.browser.msie){
     		
  			var settingsTop10 = {
     			tl: { radius: 10 },
     			tr: { radius: 10 },
   		    	bl: { radius: 0 },
      			br: { radius: 0 },
      			antiAlias: true
    		};
			curvyCorners(settingsTop10, ".cornersTop10");
  			var settings5 = {
     			tl: { radius: 5 },
     			tr: { radius: 5 },
   		    	bl: { radius: 5 },
      			br: { radius: 5 },
      			antiAlias: true
    		}; 
    		
			curvyCorners(settings5, ".corners5");
			
			//curvyCorners.adjust($mainTabs.tabs, style.backgroundColor, '#000000');
			//curvyCorners.redraw();
			
  			if ($.browser.version.substr(0,1)<8) {
   				$('.contentWindow .contentMain a').click(function() { // bind click event to link
					window.location.href = window.location.href;
					window.location.reload();
					});
								
				} 
   			};
   			
		// creates tab instances on subnav
  			$($currentSubnav).tabs($currentTab+" div.panel", { 
  				effect: 'fade',
  				fadeOutSpeed: 150, 
        		fadeInSpeed: 1000, 
  				 
  				onBeforeClick: function(event, i) {
						// get the pane to be opened
						var pane = this.getPanes().eq(i);
						if (pane.is(":empty")) {
						pane.html('<p class="loading" ><img src="/drupal/sites/all/themes/thewisdomofbees/images/ajaxLoading.gif"/></p>');
						
						// load it with a page specified in the tab's href attribute
						pane.load(this.getTabs().eq(i).attr("href") + ' .contentMain');
					}
					
	  			},
  			
  				onClick: function (index, i) {  
  					pageTracker._trackPageview(window.location.hash);
  					lhash = window.location.hash; 					
  					if (lhash.indexOf("socialize") != -1){
  					  FB.init("f540d473b76f73e9edb5a9f51159faaf");
  					  new TWTR.Widget({
  						id: 'twitterBlock',
  						version: 2,
  						type: 'profile',
  						rpp: 4,
  						interval: 6000,
  						width: 300,
  						height: 400,
  						theme: {
  						shell: {
  							background: '#ffffff',
  							color: '#000000'
  							},
  						tweets: {
  							background: '#ffffff',
  							color: '#231f20',
  							links: '#ff4b04'
  							}
	  					},
  						features: {
  							scrollbar: false,
  							loop: false,
  							live: false,
  							hashtags: true,
  							timestamp: false,
  							avatars: true,
  							behavior: 'all'
  							}
  						}).render().setUser('mnomalley').start();
  					};
  					if ($.browser.msie && $.browser.version.substr(0,1)<8) {
  						var hashString = window.location.hash;
  						hashString = hashString.replace("http://dev.thewisdomofbees.com","");
						window.location.hash = hashString;
						};
  				}
  				
  				}).history();
  				
    		}
				
		
	}).history();	
	
	


var $tabs = $mainTabs.tabs(); 

		$('#contactLink').click(function() { // bind click event to link
				lhash = window.location.hash; 
			if (lhash.indexOf("author") != -1 ) {
	
			} else {
				setTimeout("window.location.replace('/#/author/biography')",100);
				
				$tabs.bind("onBeforeClick.contactTab", function(event, tabIndex) { 
						setTimeout("window.location.replace('/#/author/contact')",100);
						$tabs.unbind("onBeforeClick.contactTab");
				});
			};
			if ($.browser.msie && $.browser.version.substr(0,1)<8) {
				window.location.reload();
			};
    		
			});
		
		$('#alertsLink').click(function() { // bind click event to link
    		lhash = window.location.hash; 
			if (lhash.indexOf("author") != -1 ) {
	
			} else {
				setTimeout("window.location.replace('/#/author/biography')",100);
				
				$tabs.bind("onBeforeClick.alertTab", function(event, tabIndex) { 
					setTimeout("window.location.replace('/#/author/sign-alerts')",100);
					$tabs.unbind("onBeforeClick.alertTab");
				});
			};
			
			if ($.browser.msie && $.browser.version.substr(0,1)<8) {
				window.location.reload();
			};
		});
		  			
		
		}); 
