

$(document).ready(function(){

	// roll-overs on main navigation
	$(function() {
		$('#rheader a').hover(function(){	
				$(this).parents('li:not(.on)').stop();	
				$(this).not('.on').css("background-image", "none");
				$(this).not('.on').css("background-color", "#47aa42");	
				$(this).parents('li:not(.on)').css("background-image", "url(/image/bg_navli.gif)");
			}, function(){
				$(this).parents('li:not(.on)').stop();
				$(this).not('.on').css("background-color", "transparent");
				$(this).not('.on').css("background-image", "url(/image/bg_navbuttons.png)");
				$(this).parents('li:not(.on)').css("background-image", "url(/image/spacer.gif)");
		});
	});
	
	// portfolio mouseovers
	$(function() {
		$('.homefoliocontainer').hover(function(){	
				$(this).find('.foliopic').animate({"opacity":"0.6"},200); 
				$(this).find('.foliotext').animate({"marginTop":"-123px", "height":"159px"},200); 
			}, function(){
				$(this).find('.foliotext').animate({"marginTop":"0", "height":"36px"},300); 
				$(this).find('.foliopic').animate({"opacity":"1"},800); 				
		});
	});
	
	// roll-overs on blog list
	$(function() {
		$('.blogsidecontainer a').hover(function(){	
				$(this).parents('li:not(.on)').stop();	
				$(this).parents('li:not(.on)').css("background-image", "url(/image/li_bullet_on.gif)");
			}, function(){
				$(this).parents('li:not(.on)').stop();
				$(this).parents('li:not(.on)').css("background-image", "url(/image/li_bullet_2.gif)");
		});
	});
	
	// peep mouseovers
	$(function() {
		$('.peepcontainer').hover(function(){	
				$(this).find('.peepquote').animate({"marginTop":"204px"},200);
			}, function(){
				$(this).find('.peepquote').animate({"marginTop":"0"},200); 			
		});
	});
	

	//blogcontainer hover	
	
	$(function() {
		$('.blogcontainer').hover(function(){	
			$('.blogcontainer').not(this).stop(true,true).css({"opacity":"0.5"});
		}, function(){
		
			$('.blogcontainer').delay(300).stop(false,true).css({"opacity":"1"});
			fixhomeblogfonts(); 
		});
	});

	$(function() {
		$('.homequotecontainer').hover(function(){	
			$('.homequotecontainer').not(this).stop(true,true).css({"opacity":"0.5"});
		}, function(){
			$('.homequotecontainer').delay(300).stop(false,true).css({"opacity":"1"});
            fixhomeblogfonts();           
		});
	});
	
	

	
	
	
	
	
	/*
	$(function() {
		$("#blogposts").hover(
		     function() {}, 
		     function() {        
		       	//$('#blogposts>li').fadeTo(200, 1.0); 
		       	$('#blogposts>li').css({"opacity":"1"});
		     }
		);
	    $("#blogposts>li").hoverIntent({
				sensitivity: 1, 
				interval: 200, 
				over: doFade, 
				timeout: 200, 
				out: doUnFade
		});
	});
	*/
	
	
	// function to show next home blog set :
	$(function() {
 		$("#nextblog").click(function () { 
				
				$('.homequotecontainer').stop(true,true).fadeTo(400, 0.4);
			
				$('.ajaxblogloader').animate({"opacity":"1"},400); 
				var _nextOffset = parseInt($('#homeblogcurrentoffset').text()) + 3;
				$('#ajreturner').load('/_ajax/homeblog/'+_nextOffset, function() {
					$('#homeblogcurrentoffset').text(_nextOffset);
  					updateHomeBlogContainers();
				});
		});
	});
	
	$(function() {
 		$("#previousblog").click(function () { 
 		
				$('.homequotecontainer').stop(true,true).fadeTo(400, 0.4);
				$('.ajaxblogloader').animate({"opacity":"1"},400); 
				var _prevOffset = parseInt($('#homeblogcurrentoffset').text()) - 3;
				$('#ajreturner').load('/_ajax/homeblog/'+_prevOffset, function() {
					$('#homeblogcurrentoffset').text(_prevOffset);
  					updateHomeBlogContainers();
				});
		});
	});
	
	
	// function to show next work set :
	$(function() {
 		$("#nextwork").click(function () { 
 				$('.foliopic>img').fadeTo(200, 0.1);
				$('.homefoliocontainer').stop(true,true).fadeTo(400, 0.3);				

				$('.ajaxworkloader').animate({"opacity":"1"},400); 

				var _nextOffset = parseInt($('#homeworkcurrentoffset').text()) + 3;
				
				$('#ajreturner').load('/_ajax/homework/'+_nextOffset, function() {
					$('#homeworkcurrentoffset').text(_nextOffset);
  					updateHomeWorkContainers();
				});
		});
	});
	
	$(function() {
 		$("#prevwork").click(function () { 
 				$('.foliopic>img').fadeTo(200, 0.1);
				$('.homefoliocontainer').stop(true,true).fadeTo(400, 0.4);
				$('.ajaxworkloader').animate({"opacity":"1"},400); 

				var _prevOffset = parseInt($('#homeworkcurrentoffset').text()) - 3;
				
				$('#ajreturner').load('/_ajax/homework/'+_prevOffset, function() {
					$('#homeworkcurrentoffset').text(_prevOffset);
  					updateHomeWorkContainers();
				});
		});
	});
	
	
	
	
	// function to show set of comments :
	$(function() {
 		$("#morecomments").click(function () { 
				$('.commentwrapper').stop(true,true).fadeTo(400, 0.4);
			
				var _totalComments = parseInt($('#blogcommentcount').text());
				
				var _nextCommentOffset = parseInt($('#blogcommentoffset').text()) + 3;
				var _urlTitle = $('#blogcommenturl').text();
				

				
				$.get('/_ajax/comment_paging/'+_urlTitle+'/P'+_nextCommentOffset, function(data) {
					$('#commentoutercontainer').append(data);

				 	$('.commentwrapper').stop(true,true).fadeTo(400, 1);
				 	$('#blogcommentoffset').text(_nextCommentOffset);
				 	
				 	$('#lesscomments').css({"display":"inline"});
				 	$('#commentdivider').css({"display":"inline"});
				 	
				 	
				 	if ((_nextCommentOffset+3)>_totalComments) {
						$('#morecomments').css({"display":"none"});
						$('#commentdivider').css({"display":"none"});
					}
				 	
				 	$.scrollTo('.offsetP'+_nextCommentOffset+':first',800);
				 	
				 	//alert(_nextCommentOffset+3)
				});
				
				
				
		});
	});
	
	// function to remove more comments :
	$(function() {
 		$("#lesscomments").click(function () { 
				$('.commentwrapper').stop(true,true).fadeTo(400, 0.4);
				
				var _removeOffSet = parseInt($('#blogcommentoffset').text());
				var _setNewOffset = parseInt($('#blogcommentoffset').text()) - 3;

				$('.offsetP'+_removeOffSet).remove();

				$('.commentwrapper').stop(true,true).fadeTo(800, 1);
				
				if (_setNewOffset == 0) {
					$('#lesscomments').css({"display":"none"});
					$('#commentdivider').css({"display":"none"});
				} else {
					$('#commentdivider').css({"display":"inline"});
					$('#morecomments').css({"display":"inline"});
				}
				
				$.scrollTo('.offsetP'+_setNewOffset+':first',800);
				
				$('#blogcommentoffset').text(_setNewOffset);
		});
	});

	// comment preview
	$(function() {
 		$("#previewcommentbutton").click(function () { 
				
				$('#cptext').html($('textarea#comment').val());
				$('#commentpreviewcontainer').fadeIn(800);
				$('#commenttextbox').text('Modify Your Comment');
				$.scrollTo('#commenttextbox',800);
				
		});
	});
	
	// form field clears
	$("#gogreen input:text").each(function(){
		if($(this).val()!='') {
			var _thisFieldIs = $(this).attr("rel")
			$('#floatin'+_thisFieldIs).fadeTo(300, 0); 
		}
	});
	
	$("#gogreen input:text").focus(function() {
		if($(this).val()=='') {
			var _thisFieldIs = $(this).attr("rel")
			$('#floatin'+_thisFieldIs).fadeTo(300, 0); 	
		}
	});
	
	$("#gogreen input:text").blur(function() {
		if($(this).val()=='') {
			var _thisFieldIs = $(this).attr("rel")
			$('#floatin'+_thisFieldIs).fadeTo(300, 1); 
		}
		clearFormFlags();
	});
	
	// comment posting ::
	var _thisurlis = $('#comment_form').attr('action');
	$('#comment_form [name=post_url]').val(_thisurlis);
	$('#comment_form [name=RET]').val('/blog/success');
	$('#comment_form [name=URI]').val('/blog/success');
		
	
	
});

clearFormFlags = function() {
	$("#gogreen input:text").each(function(){
		if($(this).val()!='') {
			var _thisFieldIs = $(this).attr("rel")
			$('#floatin'+_thisFieldIs).fadeTo(300, 0); 
		}
	});
}


getTotalHomeWorks = function() {
	// get total count of work porfolios
	$('#ajreturner').load('/_ajax/getworktotal/', function() {
			var _workCountIs = $('#ajreturner').find('#workcounting>div:last').text();
			$('#homeworktotal').text(_workCountIs);		
			if (_workCountIs <= 3) {
				$("#nextwork").css({"display":"none"});
			}
					
	});

	
}


updateHomeWorkContainers = function() {
	_totalw = parseInt($('#homeworktotal').text());
	for(var x=1;x <= _totalw;x++) {
		if($('#new'+x+'title').length) {				
			if ($('#homefolio'+x).css('display')=='none') { $('#homefolio'+x).css({"display":"inline"}, function() {$(this).animate({"opacity":"1"},400);}); }
			
			$('#hw'+x+'link').attr('href',$('#new'+x+'link').html());
			
			$('#hw'+x+'thumbimage').attr('src',$('#new'+x+'thumbimage').html());
			$('#hw'+x+'title').html($('#new'+x+'title').html());
			$('#hw'+x+'thumbheading').html($('#new'+x+'thumbheading').html());
			$('#hw'+x+'thumbsummary').html($('#new'+x+'thumbsummary').html());
		} else { $('#homefolio'+x).animate({"opacity":"0"},400); }
	}
	finishHomeWorkLoad();
}


updateHomeBlogContainers = function() {
	for(var x=1;x <= 3;x++) {
		if($('#new'+x+'title').length) {			
			if ($('#homeblog'+x).css('display')=='none') { $('#homeblog'+x).css({"display":"inline"}, function() {$(this).animate({"opacity":"1"},400);}); }
			$('#hb'+x+'link').attr('href',$('#new'+x+'link').html());
			$('#hb'+x+'title').html($('#new'+x+'title').html());
			$('#hb'+x+'subtitle').html($('#new'+x+'subtitle').html());
			$('#hb'+x+'posted').html($('#new'+x+'posted').html());
			$('#hb'+x+'date').html($('#new'+x+'date').html());
		} else { $('#homeblog'+x).animate({"opacity":"0"},400); }
	}

	finishHomeBlogLoad();
}

finishHomeBlogLoad = function() {
	var _totalResults = parseInt($('#homeblogtotal').text());
	var _currentOffset = parseInt($('#homeblogcurrentoffset').text());
	var _checknext = _currentOffset;
	$('.ajaxblogloader').animate({"opacity":"0"},0); 
	for(var i=1;i <= 3;i++) {
		if($('#new'+i+'title').length) { 
			$('#homeblog'+i).stop(true,true).fadeTo(0, 1); 
		} else {
			$('#homeblog'+i).css({"display":"none"});
			_checknext=_checknext-1;
		}
	}
	
	$('#ajreturner').html('');
	// button control
	if (_currentOffset != 0) {
		$("#prevblock").css({"display":"inline"});
		$("#previousblog").css({"display":"inline"});
		
	} else {
		$("#prevblock").css({"display":"none"});
		$("#previousblog").css({"display":"none"});
		
	}
	_finalNext = _checknext % 3;
	if (_finalNext == 0 ) {
		$("#nextblog").css({"display":"inline"});
	} else {
		$("#nextblog").css({"display":"none"});
		$("#prevblock").css({"display":"none"});
	}
	fixhomeblogfonts();	

	
}

// finish home work set loading ::
finishHomeWorkLoad = function() {
	var _totalWorkResults = parseInt($('#homeworktotal').text());
	var _currentWorkOffset = parseInt($('#homeworkcurrentoffset').text());
	
	var _checkworknext = _currentWorkOffset;
	
	$('.ajaxworkloader').animate({"opacity":"0"},400); 
	for(var i=1;i <= 3;i++) {
		if($('#new'+i+'title').length) { 
			//$('#hw'+i+'thumbimage').stop(true,true).fadeTo(200, 1);
			$('#homefolio'+i).stop(true,true).fadeTo(400,1); 
			$('#hw'+i+'thumbimage').fadeTo(800, 1);
		} else {
			$('#homefolio'+i).css({"display":"none"});
			_checkworknext=_checkworknext-1;
		}
	}
	$('#ajreturner').html('');
	
	// button control
	if (_currentWorkOffset != 0) {
		$("#workblock").css({"display":"inline"});
		$("#prevwork").css({"display":"inline"});
		
	} else {
		$("#workblock").css({"display":"none"});
		$("#prevwork").css({"display":"none"});
		
	}
	_finalWorkNext = _checkworknext % 3;
	if (_finalWorkNext == 0 ) {
		$("#nextwork").css({"display":"inline"});
	} else {
		$("#nextwork").css({"display":"none"});
		$("#workblock").css({"display":"none"});
	}
}



doFade = function() {
	$(this).siblings().not('.blogpaging').fadeTo(100, 0.3);
	//$(this).siblings().css({"opacity":"1"});
	$(this).fadeTo(300, 1.0);  
}

doUnFade = function() {
	$(this).fadeTo(200, 1.0);  
}





	/*
	$(function() {
		$('#blogposts').hover(function(){	
			$('#blogposts>li').each(function(){
				//$(this).stop(true,true).css({"opacity":"0.4"});
				
				$(this).stop(true,true).fadeTo(200, 0.4);
				
			}); 
		}, function(){
			$('#blogposts>li').each(function(){
				//$(this).stop(true, true).animate({"opacity":"1"},300); 
				$(this).stop(true, true).fadeTo(300, 1);
			});			
		});
		
		$('.blogcontainer').hover(function(){	
			//$(this).stop(true, true).animate({"opacity":"1"},300); 
			$(this).delay(100).stop(true, true).fadeTo(300, 1);
		}, function(){
			//$(this).stop(true, true).animate({"opacity":"0.4"},300); 
			$(this).stop(true, true).fadeTo(500, 0.4);
		});
	});
	
	*/


	/*
	$(function() {
		$("#blogposts").hover(
		     function() {}, 
		     function() {        
		       $('#blogposts>li').fadeTo(200, 1.0); 
		       //$('#blogposts>li').css({"opacity":"1"});
		     }
		);
	    $("#blogposts>li").hoverIntent({
				sensitivity: 1, 
				interval: 200, 
				over: doFade, 
				timeout: 200, 
				out: doUnFade
		});
	});
	*/

	/*
	$(function() {
		$('.blogcolumn1').hover(function(){	
			$('.blogcontainer').each(function(){
				//$(this).stop(true,true).css({"opacity":"0.4"});
				
				$(this).stop(true,true).fadeTo(200, 0.4);
				
			}); 
		}, function(){
			$('.blogcontainer').each(function(){
				//$(this).stop(true, true).animate({"opacity":"1"},300); 
				$(this).stop(true, true).fadeTo(300, 1);
			});			
		});
		
		$('.blogcontainer').hover(function(){	
			//$(this).stop(true, true).animate({"opacity":"1"},300); 
			$(this).delay(100).stop(true, true).fadeTo(300, 1);
		}, function(){
			//$(this).stop(true, true).animate({"opacity":"0.4"},300); 
			$(this).stop(true, true).fadeTo(500, 0.4);
		});
	});
	*/

	/*
	$(function() {
		$('.blogcontainer').hover(function(){	
				$(this).animate({"opacity":"1"},300); 
				$(this).each(function(){
					$('.blogcontainer').not(this).animate({"opacity":"0.4"},200); 
				}); 
			}, function(){
				$('.blogcontainer').each(function(){
					$(this).delay(300).animate({"opacity":"1"},300); 
				}); 			
		});
	});
	*/
	

	
	
	/* Fix Fonts for IE on Home Blogs */
	function fixhomeblogfonts() {
	   if ( $.browser.msie ) //Fixes Aliasing after opacity for IE
                {
		            $('#blogposts li').each(function(i) {
						this.style.removeAttribute('filter'); 
					});
				}  
				
	}







