  var images = new Array();
               images[0]    = "images/bannerRotate/1.jpg";
               images[9]    = "images/bannerRotate/2.jpg";
               images[8]    = "images/bannerRotate/3.jpg";
               images[3]    = "images/bannerRotate/4.jpg";
               images[4]    = "images/bannerRotate/5.jpg";
               images[5]    = "images/bannerRotate/6.jpg";
               images[6]    = "images/bannerRotate/7.jpg";
               images[1]    = "images/bannerRotate/8.jpg";
               images[2]    = "images/bannerRotate/9.jpg";
               images[7]    = "images/bannerRotate/10.jpg";
            //   images[10]   = "images/bannerRotate/boat.jpg";
               
               


 
 $(document).ready(
            function()
            {
               
                
                if(document.location.href.indexOf("/news/")==-1)
                {
                   addContent("home", "home", true);
                   addContent("about david", "david");
                  // addContent("stories from franklin", "stories");
                    addContent("photos", "photos");
                   addContent("contact", "contact");
                   
                   addStaticContent("blog","http://www.davidobyrne.net/news/news.html");
               //linkupEmptys();
                  readContent("home");
               }
            
               
               
               //$(".rightBox").corner();
             
              // banner(); //no delay
            
              
               
              /* $("#footer").positionFooter(false);*/
              
              var x="";
              if(document.location.href.indexOf("/news/")==-1)
              {
              
                  window.setTimeout("$.preloadImages(images);",4000);
                  window.setTimeout("banner();",7000);
				
				var indx=document.location.href.indexOf('?');
			   if(indx >= 0)
                           {
                              x= document.location.href.substring(indx+1);
                           
                              
                              if(x)
                                 window.setTimeout("reload('"+x+"');",500);
                                 
                           }
               }
               
               //hover styles
                $("#nav a").hover(
                    function() 
                    {
                        $(this).addClass("hover");
                    },
                    function() 
                    {
                        $(this).removeClass("hover");
                    });
           
              
            }        
);

  
function addContent(title, location, selected)
{
     var newHTML="<a id='"+location+"Nav' href='javascript:reload(\""+location+"\");'";
     if ( selected)
          newHTML+="class='selected'" ;
     newHTML+=">"+title+"</a>  ";
     $("#nav").html($("#nav").html()+newHTML);         
}
  
function addStaticContent(title, location, selected)
{
     var newHTML="<a id='"+location+"Nav' href='"+location+"' ";
     if ( selected)
          newHTML+="class='selected'" ;
     newHTML+=">"+title+"</a>  ";
     $("#nav").html($("#nav").html()+newHTML);         
}


function readContent(x)
{
   
   
    var page;
    if(!x || x=="")
        page="home";
    else page=x;
      
      
      
         $("#rightSide2").fadeOut();
          $("#divider").fadeOut();
          $("#content").fadeOut(400,function(){
          
            //dynamically load 2nd column if "sub" exists
            $("#rightSide2").load("content/"+page+".html #sub","", function(){
                
                if ( $("#rightSide2").html().length>0)
                {
                  //  $("#rightSide2").animate({width:"25%"});
                  $("#rightSide2").css("width","33%");
                   $("#leftSide").css("width","30%");
                  // $("#leftSide").animate({width:"30%"}, function(){
                       // var newConentWidth=$("#leftSide").width()-10;
                         var newConentWidth="235px";
                       //  alert(newConentWidth);
                         $("#content").css("width",newConentWidth);         
                 //   });
                    $("#rightSide2").fadeIn();
                    $("#divider").fadeIn();
                }
                else
                {
                   $("#content").css("width","510px");
                   
                    $("#leftSide").animate({width:"55%"});
                    
                    
                }
                
            });
            
            
                
            $("#content").load("content/"+page+".html #main","",function(){afterContentLoad(x);});
            
        
    });
    // $("#content").load("content/"+page+".html");
}


function reload(x)
{
      var page;
      if(!x||x=="")
        page="home";
        
       if(x&& x.indexOf("merchant_return")>=0)
        page="thanks";
        
    else page=x;
    readContent(page);
    setNavStyle(page);
}


function setNavStyle(x)
{
   

     $("#nav a").removeClass("selected");

     $("#"+x+"Nav").addClass("selected");
    
}

 
function afterContentLoad(x)
{
    if(x)
        setNavStyle(x);
     
     //hack for blog
     
     
     if(x&&x=="home")
     {
          addBlog(500);
     }
    
    //email if there
     $("#email").attr("href","mailto:david"+"@"+"davidobyrne.net");
     $("#email").html("david"+"@"+"davidobyrne.net");
      $("#email").css("text-transform","none");
    
    //photos if there
     if(x=="photos")
     {
          var newHtml="";
          for (var i = 0;i<photoImages.length;i++)
         {
	  
	    if(i>11)
	    {  //$('#jbrek').append("'"+photoImages[i]+"'");
		$('#jbrek').append(getPhotoHtml(i));
	    }
	    else
	    $('#loader').append(getPhotoHtml(i));
             //  newHtml+=getPhotoHtml(i);
          };
          
	  
         // $('#loader').html(newHtml);
          $('#gallery a').lightBox();
     }
     
     //labels if there
   
    
    
    $("#content").fadeIn();
    
    
 }
 
function addBlog(blogsize)
{
   $("#content").load("news/news.html .post","",function()
      {
          $(".post").each(function(){
         
                 var newHTML =$(this).html();
                // alert(newHTML);
                 if(newHTML.length > blogsize)
                 {
                    newHTML=newHTML.substring(0,blogsize)+"...";
                      var newLink=$(this).find(".post-footer-link").attr("href");
                  
                   
                    newHTML=newHTML+"<br/><a href='"+newLink+"'>read more</a>";
                 }
              
                 $(this).html(newHTML);
                 
         });
         
         $("#content").prepend("<h1>blog</h1>")
      });
       
}
 
jQuery.preloadImages = function(a)
{
  for(var i = 0; i<a.length; i++)
  {
    jQuery("<img>").attr("src", a[i]);
  }
}

function linkToDavid()
{
    var html='<div style="height:150px;width:400px;">Copy the and paste the html below into your blog or website to link to this website and suport David&apos;s campaign <Br/>'+
    '<Br/><input id="linkInput" type="text" style="width:350px;" value="&lt;a href=&apos;http://davidobyrne.net/&apos; &gt;David O&amp;apos;Byrne&lt;/a&gt;"/></div>';
     new Boxy(html, {title: 'Link To David!', draggable: false, modal: true}).show();
     
     window.setTimeout('$("#linkInput").focus().select();',100);
}

function loadUTube(href,title)
{
     var html='<object width="560" height="340"><param name="movie" value="'+href+'&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+href+'&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object>';
     new Boxy(html, {title: title, draggable: false, modal: true}).show();

}

function linkupEmptys()
{
     $("#rightBox a").attr("href","javascript:;");
     $("#content a").attr("href","javascript:;");
}


//EXTRACT TO BANNER PLUGIN BELOW

            function banner(x)
            {
                var fadeSpeed=700;
                var wait=7000;
                
                var stop=false;             // need obj model
                //   start delaw             window.setTimeout("banner();",5000);
               var currentIndex=0;
              
                $("#rotator").each(function()
                {
                    $(this).fadeTo(fadeSpeed,0.05,function()
                    {
                         
                        var x=$(this).attr("src");
                        for (currentIndex=0;currentIndex<images.length;currentIndex++)
                        {
                              if (images[currentIndex]==x)
                                   break;
                        }
                         currentIndex++;
                         if (currentIndex >= images.length)
                              currentIndex=0;
                        
                        $(this).attr("src",images[currentIndex]);
                        $(this).fadeTo(400,1);
                    }
                    );
                    
                });
                
                if(!stop)
                    window.setTimeout("banner();",wait);
            }
            
function getPhotoHtml(x)
{
     var photoHTML='<li>'+
                    '<a href="images/photos/'+photoImages[x]+'" title="'+photoDescriptions[x]+'">'+
                        '<img src="images/photos/thumbs/'+photoImages[x]+'"  alt="'+photoDescriptions[x]+'" />'+
                    '</a>'+
                '</li>';
     return photoHTML;
}

function register()
{
  
   var error=false;
   $(".required").each(function()
                       {
                           if(this.value.length==0)
                              error=true;
                       });
    
   if (error)
      $(".error").html("please fill out required fields.");
   else
   {
      var B="";
      $("input").each(function(){B+=this.id+" : "+this.value+ ", "});
      
      var S="Please register me";
      var mailAdd1="mel";
      var mailAdd2="davidobyrne.net ";
      
      document.location="mailto:"+mailAdd1+"@"+mailAdd2+"?subject="+S+"&body="+B;
   }
   
}

function changeDonation(ammount)
{
	
	if(parseInt(ammount)==0)
		ammount=  $("#other").val();
   $("input[name=amount]").val(ammount);
}


            
            