// helper functions for portfolio
// Author: Nathan Burnett
// Date : 9-16-10

// Initialize vars

var $container = null;
var $panels = null;

var scrollOptions;
var isResizeEvent = false;
var pageSize = 850;

var currentPanel = null;

var currentHideItemSet = null;
var currentShowItemSet = null;
var previousItemSetPos = 0;


//start modal options

// end modal options


// start functions

/**
 * This function creates and starts everything needed to control the sliding
 * of pages
 */
function initPageSlider(){
  // start page scrolling 
  
  // calculate extra padding needed based on the screen size
  var w = $( '#mainPagesWrapper' ).width();
  var p = Math.floor(( w - pageSize ) / 2);
  
  // get the pages and store them as well as the container
  $panels = $( '#mainPagesWrapper .scrollContainer div.page' );
  $container = $( '#mainPagesWrapper .scrollContainer');
  
  // setup the padding for each page , Need to bind an on window resize function to reset
  // these values; 
  $panels.css( { paddingLeft : p + 'px' , paddingRight : p + 'px' });
  
  var horizontal = true; // 
  
  // calculate and reset the width of the container again need to make a resize window function
  $container.css( 'width' , $panels[0].offsetWidth * $panels.length );
   
  //create the scroll object apply overflow
  var $scroll = $('#mainPagesWrapper .scroll').css('overflow', 'hidden');
  
  // handle the nav selection need to modify this just as a place holder for code example
  function selectNav() {
    // var temp = $(this).parents("#navigation").find('a');
    // $(temp).animate({color:"#eee"},300);
    // $(this).animate({color:'#913D14'},300);
  }
  
  // go find the navigation link that has this target and select the nav
  function trigger(data) {
    var el = $('#navigation ul').find('a[href$="' + data.id + '"]').get(0);
    selectNav.call(el);
  }
  
  // check to see if something was bookmarked and select it
  if (window.location.hash) {
    trigger({ id : window.location.hash.substr(1) });
  } else {
    $('#navigation a:first').click();
  }
  
  // set up the offset to make sure everything is aligned properly. also it checks to 
  // see if horizontal is true or not for future expansion possibly.
   var offset = parseInt((horizontal ? 
        $container.css('paddingTop') : 
        $container.css('paddingLeft')) 
        || 0) * -1;
  
  // set up scrolling options
  scrollOptions = {
        target: $scroll, // the element that has the overflow       
        items: $panels, // can be a selector which will be relative to the target        
        navigation: '#navigation ul li a',
        axis: 'x',// allow the scroll effect to run both directions
        // and on before to track the current panel for the resize
		onBefore: function(e, target, $tobescrolled,$panelset,panelpos){
			//currentPanel = pos;
			
			for(var i = 0 ; i < $panels.length; i++)
			{
				if($(target).attr('id') == $($panels[i]).attr('id'))
				{
					currentPanel=i;
				}
			}
			
			//google code
			if(!isResizeEvent)
			{
				 _gaq.push(['_trackPageview', "/vpv/"+$(target).attr('id')]); 
				
				
			}
			else
			{
				isResizeEvent = false;
				
			}
			
		},
        onAfter: trigger, // our final callback ( probably should change this to before for looks)
        offset: offset,
        duration: 750,// duration of the sliding effect
        easing: 'easeInOutQuad' // need to make this the one we want for all pages
      };
  
  // apply serialScroll
  $('#mainPagesWrapper').serialScroll(scrollOptions);
  
  
  $("#navigation ul li a").click(function(){
    var temp = $(this).parents("#navigation").find('a');
    $(temp).animate({color:"#eee"},100);
    $(this).animate({color:'#913D14'},150);
  })
  
	$(window).resize(function(){
		 var w = $( '#mainPagesWrapper' ).width();
 		 var p = Math.floor(( w - pageSize ) / 2);
		$panels.css( { paddingLeft : p + 'px' , paddingRight : p + 'px' });
		
		// calculate and reset the width of the container again need to make a resize window function
		$container.css( 'width' , $panels[0].offsetWidth * $panels.length ); 
		
		//scroll to current panel.
		//alert(currentPanel);
		isResizeEvent = true;
		$($container).trigger('goto', [currentPanel]);
		
  });
  
 $.localScroll(scrollOptions);
}

/**
 * this function initializes the home scroller and its options
 */
function initHomeScroller(){
  
	    $(".homeNavButton").css({opacity:".3"});
	    
	    $(".homeNavButton").hover(function(){
	      //over
	      $(this).animate({opacity:"1"},250);
	    },
	    function(){
	      //out
	      $(this).animate({opacity:".3"},250);
	    });
	    
	    var $homeScrollerPanelWrapper = $("#homeScrollerWrapper #homeScrollerPanelWrapper");
	    
	    var $homeScrollerPanels = $homeScrollerPanelWrapper.find(".homeScrollerPanel");
	    
	    $homeScrollerPanelWrapper.css({width:$homeScrollerPanels[0].offsetWidth*$homeScrollerPanels.length+"px"});
	    
	    var homeScrollerOptions ={
	      target:'#homeScrollerWrapper',
	      items:'.homeScrollerPanel',
	      next:'.rightButton',
	      prev:'.leftButton',
	      duration:600,
	      force:true,
	      axis:'x',
	      easing:'easeInOutQuad'
	    };
	    
	    $("#homeScrollerOuterWrapper").serialScroll(homeScrollerOptions);
      
}

/**
 * This function initializes all animations
 */
function initAnimation(){
  
  $(".loadingWrapper").fadeOut(300,function(){
    // replace initial values
    
    $($container).trigger('next');
    $("body").css({overflowY:"auto"});
    // show header
    $('#header').animate({
      top:['+=165px', 'easeOutCubic']
    },800,function(){
      //animate menu items
      var menuItems = $("#navigation ul li");
      
      //start menu animation
      $("#navigation").fadeIn(600);
      $(".loginSliderButton").fadeIn(600);
    });
  });
  //scrollOptions.easing = "easeInOutCubic";
  //scrollOptions.duration = "700";
  
}

function iterateMenuAnimation(menuItems, pos)
{
  $(menuItems[pos]).animate({opacity:1},250,function(){
    iterateMenuAnimation(menuItems,++pos);
  });
}

/**
 * This function binds the contact form
 */
function initContactForm(){
  $("#contactForm").submit(function(){
        
        $.post('wp-content/themes/portfoliov2/sendMessage.php',$("#contactForm").serialize() ,function(data){
          var json = eval("("+data+")");
          if(json.status=="success")
          {
            //fade out form display something else
            $("#contactForm").fadeOut(400,function(){
              //display thanks
              $("#sendConfirmation").fadeIn(400); 
            });
          }
          else
          {
            
            if(json.errors.nameError.length>0)
            {
              $("#nameLabel").children(".required").children(".error").html(json.errors.nameError); 
            }
            if(json.errors.emailError.length>0)
            {
              $("#emailLabel").children(".required").children(".error").html(json.errors.emailError); 
            }
            if(json.errors.phoneError.length>0)
            {
              $("#phoneLabel").children(".required").children(".error").html(json.errors.phoneError); 
            }
            if(json.errors.subjectError.length>0)
            {
              $("#subjectLabel").children(".required").children(".error").html(json.errors.subjectError); 
            }
            if(json.errors.messageError.length>0)
            {
              $("#messageLabel").children(".required").children(".error").html(json.errors.messageError); 
            }
          }
        });
        
        return false;
      });
}


/**
 * This function initializes the bindings for the blog section
 */
function initBlog(){
  // bind blog title click
  $(".blogItem").click(function(){

    

    tempID = $(this).attr('title');
	var article = $.trim($(this).html());
    $.ajax({

      url: 'wp-content/themes/portfoliov2/ajaxFunctions.php?area=blog&method=getPostById&post_id='+tempID,
      beforeSend:function(){
        // show loading
        $(".blogLoader").fadeIn(300);
        
      },
      success: function(data) {
          
          var json = eval("("+data+")");
          var permalink = json.permalink;
          var html = json.html;
          
          
          $("#mainBlogPage").fadeOut(400,function(){
            $("#blogInsertDiv").html(html);
            $("#commentForm #comment_post_id").val(tempID);
            $(".blogLoader").fadeOut(150);                
            $("#singleBlogView").fadeIn(500);
            
          });
          
          //_gaq.push(['_trackEvent', 'ArticleViews', 'Blog Entry',permalink]);
          _gaq.push(['_trackPageview', permalink]);
      }

    });

    

   });
  
  // bind blog read more click
  $(".readMore").click(function(){
    tempID= $(this).attr('title');
    var article = $.trim($(this).html());
        $.ajax({

      url: 'wp-content/themes/portfoliov2/ajaxFunctions.php?area=blog&method=getPostById&post_id='+tempID,

      success: function(data) {
		var json = eval("("+data+")");
        var permalink = json.permalink;
        var html = json.html;
       	
       	$("#mainBlogPage").fadeOut(500,function(){
			$("#blogInsertDiv").html(html);
            $("#commentForm #comment_post_id").val(tempID);
            $(".blogLoader").fadeOut(150);                
            $("#singleBlogView").fadeIn(500);
       	});
       	
       	_gaq.push(['_trackPageview', permalink]);

      }

    });              

   });

  // bind back to main Blog click
  $("#backToMainBlogView").click(function(){

       $("#singleBlogView").fadeOut(500,function(){

          
  
                          

          $("#mainBlogPage").fadeIn(500);

       });                 

   });
   
   //bind contact form submit
   $("#commentForm").submit(function(){
    
    $.post('wp-content/themes/portfoliov2/ajaxFunctions.php?method=postComment',
          $("#commentForm").serialize() ,
        function(data){
            //call back
          var json = eval("("+data+")");
          
          if(json.status=="success")
          {
            var now = new Date();
            var nowText = dateFormat(now,"mmmm dd, yyyy");
            
            
            //start generated dom
            var div1=document.createElement('div');
            div1.setAttribute("style","display:none");
            div1.setAttribute('id','commentsWrapper');
            var div2=document.createElement('div');
            div2.className='left userIconWrapper';
            div1.appendChild(div2);
            var div3=document.createElement('div');
            div3.className='userIcon';
            div2.appendChild(div3);
            var div4=document.createElement('div');
            div4.className='left individualCommentInformation';
            div1.appendChild(div4);
            var div5=document.createElement('div');
            div5.className='commentMetaData';
            div4.appendChild(div5);
            var span1=document.createElement('span');
            span1.className='author';
            div5.appendChild(span1);
            var txt8=document.createTextNode(json.author);
            var spaceDiv = document.createElement("span");
            $(spaceDiv).html("&nbsp;&nbsp;");
            span1.appendChild(txt8);
            span1.appendChild(spaceDiv);
            var span2=document.createElement('span');
            span2.className='date';
            div5.appendChild(span2);
            var txt10=document.createTextNode(nowText);
            span2.appendChild(txt10);
            var div6=document.createElement('div');
            div6.className='commentText';
            div4.appendChild(div6);
            var txt14=document.createTextNode(json.comment);
            div6.appendChild(txt14);
            
            
            var div7=document.createElement('div');
            div7.className='clear';
            div1.appendChild(div7);
            var div8=document.createElement('div');
            div8.className='break';
            div1.appendChild(div8);

            //alert($(div1).height());
            
            $("#comments").append(div1);
            $(div1).slideDown(300);
            var pid = $("#comment_post_id").val();
            document.getElementById("commentForm").reset();
            $("#comment_post_id").val(pid);
            
            //update nums

            
            var commentNumbers = $(".numComments"+pid);
            $(".numComments"+pid).fadeOut(20);
            for(var i=0;i<commentNumbers.length;i++)
            {
  //            alert($(commentNumbers[i]).html());
              var newNum ="";
              var t = $(commentNumbers[i]).html().toString().split(" ","1");
              //alert("length of t:"+t.length+"\nvalue:"+t[0].toString());
              if(t[0]==0)
              {
                newNum = (parseInt(t[0])+1)+" comment";
              }
              else 
              {
                newNum = (parseInt(t[0])+1)+" comments";
              }
//              alert(newNum);
              
              $(commentNumbers[i]).html(newNum);  
            }

            $(".numComments"+pid).fadeIn(400);
            
            _gaq.push(['_trackEvent', 'Comments', 'Comment Posted','Author:'+json.author+'-Date:'+nowText]);
            
              
          }
          else
          {
            
          }
          
          }
    );
    
    return false; 
   });

}

/**
 * this function initializes the entire portfolio page
 */
function initPortfolio(){
  // init accordion
          $("#portMainMenu").accordion({active:'.accordionHeaderFirst'});  ;
           
          // set container widths
         
          $('#webDesignScrollContainer .horizontalScrollContainer .horizontalScroll').css( 'width',$('#webDesignScrollContainer .horizontalScrollContainer .horizontalScroll .portPanel')[0].offsetWidth * $('#webDesignScrollContainer .horizontalScrollContainer .horizontalScroll .portPanel').length );
          $('#wordpressScrollContainer .horizontalScrollContainer .horizontalScroll').css( 'width',$('#wordpressScrollContainer .horizontalScrollContainer .horizontalScroll .portPanel')[0].offsetWidth * $('#wordpressScrollContainer .horizontalScrollContainer .horizontalScroll .portPanel').length );
          $('#webAppsScrollContainer .horizontalScrollContainer .horizontalScroll').css( 'width',$('#webAppsScrollContainer .horizontalScrollContainer .horizontalScroll .portPanel')[0].offsetWidth * $('#webAppsScrollContainer .horizontalScrollContainer .horizontalScroll .portPanel').length );
          $('#jqueryPluginScrollContainer .horizontalScrollContainer .horizontalScroll').css( 'width',$('#jqueryPluginScrollContainer .horizontalScrollContainer .horizontalScroll .portPanel')[0].offsetWidth * $('#jqueryPluginScrollContainer .horizontalScrollContainer .horizontalScroll .portPanel').length );
          
          // create scrolling options
          var menuVerticalScrollSpeed = 400;
          var menuHorizontalScrollSpeed = 400;
          var horizConstant = true;
          var horizEase = "easeInOutQuad";
          
          var portVerticalScrollOptions = {
            items: '.row',
            axis: 'y',
            navigation:'.verticalScrollMenu li a',
            duration:menuVerticalScrollSpeed,
            force:false,
            easing:'easeInOutQuad',
            constant:true,
            onBefore:function( e, elem, $pane, $items, pos )
            {
              
              var tsid = $($items[pos]).attr('id').replace("ScrollContainer","");
              
              var thid = $($items[previousItemSetPos]).attr('id').replace("ScrollContainer","");
              
              if(tsid!=thid)
              {
                //changeBottomNav
                changeBottomBar(thid,tsid);
                
                //now keep track since its the current one
                previousItemSetPos = pos;  
                var tSection = $(elem).attr('id');
                var section = tSection.replace("ScrollContainer","");
                //alert(section);
                _gaq.push(['_trackEvent', 'Portfolio', 'SectionView',section]);

              }
              
            }
          };
          
          
          
          
          var portHorizontalWebDesignScrollOptions = {
            
            items: '.portPanel',
            axis: 'x',
            navigation:'#webDesignThumbWrapper .thumbnails li a',
            duration:menuHorizontalScrollSpeed,
            force:true,
            onBefore:function( e, elem, $pane, $items, pos ){
            	_gaq.push(['_trackEvent', 'Portfolio', 'ItemView',$(elem).attr('id')]);
            },
            constant:horizConstant,
            
            easing:horizEase
          };
          var portHorizontalWordpressScrollOptions = {
            
            items: '.portPanel',
            axis: 'x',
            navigation:'#wordpressThumbWrapper .thumbnails li a',
            duration:menuHorizontalScrollSpeed,
            force:true,
            onBefore:function( e, elem, $pane, $items, pos ){
            	_gaq.push(['_trackEvent', 'Portfolio', 'ItemView',$(elem).attr('id')]);
            },

            constant:horizConstant,
            
            easing:horizEase
          };
          var portHorizontalWebAppScrollOptions = {
            
            items: '.portPanel',
            axis: 'x',
            navigation:'#webAppsThumbWrapper .thumbnails li a',
            duration:menuHorizontalScrollSpeed,
            force:true,
            onBefore:function( e, elem, $pane, $items, pos ){
            	_gaq.push(['_trackEvent', 'Portfolio', 'ItemView',$(elem).attr('id')]);
            },
            constant:horizConstant,
            
            easing:horizEase
          };
          var portHorizontalJqueryScrollOptions = {
            
            items: '.portPanel',
            axis: 'x',
            navigation:'#jqueryPluginThumbWrapper .thumbnails li a',
            duration:menuHorizontalScrollSpeed,
            force:true,
            onBefore:function( e, elem, $pane, $items, pos ){
            	_gaq.push(['_trackEvent', 'Portfolio', 'ItemView',$(elem).attr('id')]);
            },
            constant:horizConstant,
            
            easing:horizEase
          };
                   
          // initialize all scrollers
          
          $("#verticalScroll").serialScroll(portVerticalScrollOptions);

          $("#webDesignScrollContainer .horizontalScrollContainer").serialScroll(portHorizontalWebDesignScrollOptions);
          $("#wordpressScrollContainer .horizontalScrollContainer").serialScroll(portHorizontalWordpressScrollOptions);
          $("#webAppsScrollContainer .horizontalScrollContainer").serialScroll(portHorizontalWebAppScrollOptions);
          $("#jqueryPluginScrollContainer .horizontalScrollContainer").serialScroll(portHorizontalJqueryScrollOptions);
          
          
          //bind nav click ui functions
          $(".verticalScrollMenu li a").click(function(){
            var tItem = this;
            $(".verticalScrollMenu li a").animate({color:'#EEEEEE'},200,function(){
              $(tItem).animate({color:'#762A3F'},200);  
            });
            
          });
          
          // set up bottom thumbnail animations
          
          //$('.thumbnails li').css({opacity:".4"});
          //$('.thumbnails li.activeThumb').css({opacity:"1"});
          
          // $('.thumbnails li').hover(function(){
          //   // over
          //   if($(this).hasClass(".activeThumb"))
          //   {
          //     
          //   }
          //   else
          //   {
          //     $(this).animate({opacity:1});
          //   }
          //   
          // },
          // function(){
          //   // out
          //  
          //   if($(this).hasClass("activeThumb"))
          //   {
          //     
          //   }
          //   else
          //   {
          //     $(this).animate({opacity:.4},300);
          //   }
          // });
          // 
          //animation tracking
         
          //bind hover and modal events
          $(".portExampleImage").hover(function(){
          	//over
          	$(this).find(".imgHoverEffect").fadeIn(200);
          	
          	$(this).find(".enlargeBanner").animate({bottom:"116px"},450);
          },
          function(){
          	//out
          	$(this).find(".imgHoverEffect").fadeOut(200);
          	$(this).find(".enlargeBanner").animate({bottom:"-87px"},300);
          })
          
		$(".enlargeBanner").click(function(){
			
			var imgSet = $(this).attr('title');
			//alert(imgSet);
			
			var imgs = new Array();
			var countImgs = 0;
			$.get('/sandbox/wordpress/wp-content/themes/portfoliov2/imgSets/'+imgSet+'.json', function(data) {
				  var imgJson = eval("("+data+")");
				  for(var i=0;i<imgJson.images.length;i++)
				  {
				  	imgs[i]=imgJson.images[i].image;
				  }
				  $.fancybox(imgs,{
					'padding'			: 0,
					'transitionIn'		: 'elastic',
					'transitionOut'		: 'elastic',
					'type'              : 'image',
					'changeFade'        : 2
				});
			});
			
			
			
          	
			
		});
         
	 
}

function hideTray(nid)
{
    //alert("before : "+nid);
    var thumbItems = $('#' + nid + 'ThumbWrapper .thumbnails li');
    
    currentThumbWrapper = '#' + nid + 'ThumbWrapper';
    currentItemSet = thumbItems;
    currentItemSetPos = 0;
    iterateHide();
}

function changeBottomBar(thid,tsid)
{
  // animate thidThumbWrapper out
  var itemsToHide = $("#" + thid + "ThumbWrapper .thumbnails li");
  
  var itemsToShow = $("#" + tsid + "ThumbWrapper .thumbnails li");
  
  iterateHide(itemsToHide,0,thid,tsid,itemsToShow);
  
}      

// iterate to animate
function iterateHide(itemsToHide, curPos,thid,tsid,itemsToShow){
      
  if(itemsToHide == null)
  {
    
  }
  else
  {
    $(itemsToHide[curPos]).animate({
      bottom:'-125px'
    },150,function(){
      if( (itemsToHide.length-1) == curPos )
      {
        
        
        $("#" + thid + "ThumbWrapper").css({display:'none'});
        
        //initialize next one to be ready for animation
        $("#" + tsid + 'ThumbWrapper .thumbnails li').css({bottom:"-125px"});
        $("#" + tsid + "ThumbWrapper").css({display:'block'});
        iterateShow(itemsToShow , 0, thid , tsid);
        
      }
      else
      {
        iterateHide(itemsToHide,++curPos,thid,tsid,itemsToShow);
      }
    });
  }
}
      
// iterate show
function iterateShow(itemsToShow, curPos, thid, tsid)
{
  if( itemsToShow == null )
  {
    
  }
  else
  {
    $(itemsToShow[curPos]).animate({
      bottom:'0px'
    },150,function(){
      if( (itemsToShow.length-1) == curPos )
      {
                     
      }
      else
      {
        
        iterateShow(itemsToShow, ++curPos, thid, tsid);
      }
    });
  }
}

/**
 * test
 */
 var $blogthing;
 
 var currentBlogPanel = 0;
function initBlog2(){

 
     $(".blogMenuWrapper").css({height:$(".mainBlogWrapper").height()});
  	$("#backToMainBlog").click(function(){
		$(".singleBlogEntryOuterWrapper").fadeOut(800);
		 $(".blogScroller").animate({left:"0px",easing:"easeInQuad"},600,function(){
		 	
		 });
	     
	});
	
	 $(".blogItem").click(function(){

	    tempID = $(this).attr('title');
		var article = $.trim($(this).html());
	    $.ajax({
	
	      url: 'wp-content/themes/portfoliov2/ajaxFunctions.php?area=blog&method=getPostById&post_id='+tempID,
	      beforeSend:function(){
	        // show loading
	        //$(".blogLoader").fadeIn(300);
	        //$("#blogScrollWrapper").trigger('next');
	        $(".blogScroller").animate({left:"-620px",easing:"easeInQuad"},600);
	        
	      },
	      success: function(data) {
	          
	          var json = eval("("+data+")");
	          
	          var permalink = json.permalink;

	          //assign values
	          _gaq.push(['_trackPageview', permalink]);
	          //$("#mainBlogPage").fadeOut(400,function(){
	           // $(".insertDiv").html(html);
	            $("#comment_post_id").val(tempID);
	            //$(".blogLoader").fadeOut(150);                
	            

	$("#singleBlogEntryTitle").html(json.post_title);
	$("#singleBlogEntryText").html(json.post_content);
	$("#numberComments").html(json.comment_count+" comments") ;
	
	var numComments = json.comments;
	$("#commentsInsertWrapper").html("");
	for(var i=0; i<json.comments.length;i++)
	{
		var tHTML = '<!-- start comment entry -->'+
			'<div class="commentEntry">'+
			'	<div class="commentIcon">'+
				
			'	</div>'+
			'	<!-- start comment wrapper -->'+
			'	<div class="commentTextWrapper">'+
			'		<div class="commentInfo">'+
			'			<span class="commentAuthor">'+
				json.comments[i].comment.comment_author+
			'			</span>'+
			'			<span class="commentDate">'+
				json.comments[i].comment.comment_date+
			'			</span>'+
			'		</div>'+
			'		<div class="commentText">'+
				json.comments[i].comment.comment_content+
			'		</div>'+
			'	</div>'+
			'	<!-- end comment text wrapper -->'+
			'	<div class="clear"></div>'+
			'</div>'+
			'<!-- end comment entry -->';
			
			
			$("#commentsInsertWrapper").append(tHTML);
			
	}
	
	
 
	
   $(".singleBlogEntryOuterWrapper").fadeIn(1200,function(){
   	
	//$(".blogMenuWrapper").animate({height:$(".mainBlogWrapper").height()});
   });

	      }      
	          });
	          
	          //_gaq.push(['_trackEvent', 'ArticleViews', 'Blog Entry',permalink]);
	          
     

    });

    

   
	 //bind contact form submit
   $("#commentForm").submit(function(){
    
    $.post('wp-content/themes/portfoliov2/ajaxFunctions.php?method=postComment',
          $("#commentForm").serialize() ,
        function(data){
               //call back
			   var now = new Date();
            var nowText = dateFormat(now,"mmmm dd, yyyy");
            
          var json = eval("("+data+")");
          
          if(json.status=="success")
          {
            var tHTML = '<!-- start comment entry -->'+
			'<div class="commentEntry tempFade">'+
			'	<div class="commentIcon">'+
				
			'	</div>'+
			'	<!-- start comment wrapper -->'+
			'	<div class="commentTextWrapper">'+
			'		<div class="commentInfo">'+
			'			<span class="commentAuthor">'+
				json.author+
			'			</span>'+
			'			<span class="commentDate">'+
				nowText+
			'			</span>'+
			'		</div>'+
			'		<div class="commentText">'+
				json.comment+
			'		</div>'+
			'	</div>'+
			'	<!-- end comment text wrapper -->'+
			'	<div class="clear"></div>'+
			'</div>'+
			'<!-- end comment entry -->';
			
			$("#commentsInsertWrapper").append(tHTML);
			$(".tempFade").slideDown(700,function(){
				//$(".blogMenuWrapper").animate({height:$(".mainBlogWrapper").height()});
				
			});
			 _gaq.push(['_trackEvent', 'Comments', 'Comment Posted','Author:'+json.author+'-Date:'+nowText]);
          }
          else
          {
            
          }
          
        }
    );
    
    return false; 
   });
  
  
}

function setSingleBlogEntryValues(json){
	
}

/**
 * Init services animations
 */
 var proccessOpen = false;
function initServices(){
  
  $(".proccessToggle").click(function(){
    
    if(proccessOpen==false)
    {
      //open
      $("#mainProccessWrapper").slideDown(700);
      $(".viewMyProccessText").fadeOut(250,function(){
        $(".myProccessText").fadeIn(250);
      });
      proccessOpen=true;
    }
    else
    {
      //close
      $("#mainProccessWrapper").slideUp(700);
      $(".myProccessText").fadeOut(250,function(){
        $(".viewMyProccessText").fadeIn(250);
      });
      proccessOpen=false;
    }
  });

}

var pagesToLoad=new Array("work","services","about");

/**
 * This initializes everything
 */
function bootStrap(){
  // initialize page scroller
  initPageSlider();
  
  // initialaize home panel scroller 
  initHomeScroller();
  // initialize animations
  initAnimation();  
  
  
  // initialize contact form
  //initContactForm();
  
  // initialize blog section
  //initBlog();
  initBlog2();
  // init Portfolio
  //initPortfolio();
  

  
  
  //get rest of pages
  iterate_page_loads(pagesToLoad,0);
  
  // apply local scroll to take care of any other links
  $("#navigation").localScroll(scrollOptions);
	var sc = document.createElement('script');
	sc.type = 'text/javascript';
	sc.src = 'http://nbwebdevelopment.com/sandbox/wordpress/wp-content/themes/portfoliov2/js/jquery.simplemodal-1.4.js';
	document.getElementsByTagName('head')[0].appendChild(sc);
  
}



function iterate_page_loads(pagesToLoad,itemPos)
{
  //alert("here");
  if(itemPos < pagesToLoad.length)
  {
  $.ajax({

      url: 'wp-content/themes/portfoliov2/ajaxFunctions.php?area=loading&method=retrieve_page&page_name='+pagesToLoad[itemPos],
      // beforeSend:function(){
      //   // show loading
      //   $(".blogLoader").fadeIn(300);
      // },
      success: function(data) {
          
          $("#"+pagesToLoad[itemPos]).html(data);
          if(pagesToLoad[itemPos]=="work")
          {
            initPortfolio();
          }
          if(pagesToLoad[itemPos]=="about")
          {
            initContactForm();
          }
          if(pagesToLoad[itemPos]=="services")
          {
            initServices();
          }
      },
      complete: function(){
        iterate_page_loads(pagesToLoad,(itemPos+1));
      }

    });
  }
}



