$(document).ready(function() {
   setContentHeight();
   if($('#home-gallery').length){
	   init_gallery();
	}
	if($('#portfolio').length){
		init_portfolio();
	}
	if($('#feedback').length){
		init_feedback();
	}
});

//NAVIGATION
function init_code_nav(){
	$.each($('.code-nav'),function(){
		$(this).click(function(){
				$.post($(this).attr('id')+".php",function(data){
					$('#innerContent').html(data);
					setContentHeight();
					SyntaxHighlighter.all();
				});
				
			});
		
	});
}

//PAGE CONTENT HEIGHT
function setContentHeight()
{
	var pageSize = getPageSize();
	
	$('#outerFrame').height((pageSize[3] - 16)); //+'px'
 	$('#content').height(parseInt($('#outerFrame').height()) - 52); // +'px';
 	$('#innerContent').height(parseInt($('#content').height()-91)); // + "px";
	
	$('#pic').offset({'left':parseInt($('#content').offset().left) - 91}); // + "px";
	$('#pic').offset({'top':parseInt($('#content').offset().top) + 2}); // + "px";
	
	if(navigator.userAgent.indexOf('IE') != -1)
	{
		$('#pic').offset({'left':parseInt($('#content').offset().left) - 93}); // + "px";
		$('#pic').offset({'top':parseInt($('#content').offset().top)- 2}); // + "px";
	}
	if(navigator.userAgent.indexOf('Chrome') != -1)
	{
		$('#pic').offset({'left':parseInt($('#content').offset().left) - 91}); // + "px";
		$('#pic').offset({'top':parseInt($('#content').offset().top)+1}); // + "px";  
	}
}


// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function init_gallery(){
	$('#arrow-back').click(function(){changeImages("back");});
	$('#arrow-forward').click(function(){changeImages("forward");});
}
function changeImages(direction) {
	if (document.images) {
		//change = 4,8,11
		var imgArray = ["3","9","14","6","10","1","5","15","7","12","2","13","4","8","11"];
				
		for(var i=1;i<4;i++)
		{
			var img = $("#img"+i);
			var gall = img.attr('src').substr((img.attr('src').indexOf("gallery") +15));
            var num = gall.substring(0,gall.indexOf("."));
            			
			var ind = imgArray.indexOf(num);
			var index = (direction == 'forward' ? (ind > 8 ? (ind -9) : ind + 3) : (ind < 3 ? (ind + 9) : ind - 3));
			
			document["gallery_" + i].src = "images/gallery/gallery" + imgArray[index] + ".gif"; 
		}
	}
}

//PORTFOLIO
function init_portfolio(){ 
	var $slider = $('#portfolio');
	$slider.dbdgallery({
		width:500,
		height:330,
		imgDir:'images/portfolio',
		imgNames:['phfSS1.jpg','phfSS2.jpg','ocwaSS1.jpg','ocwaSS2.jpg','fsnc1.jpg','fsnc2.jpg','aeps1.jpg','aeps2.jpg','herbs-plus1.jpg','herbs-plus2.jpg','hive-thinking1.jpg','hive-thinking2.jpg','ugsoaSS.jpg','tlap.jpg','xmasCoalSS1.jpg','xmasCoalSS2.jpg','xmasCoalSS3.jpg','gallery1.gif','gallery2.gif','gallery3.gif'],
		imgLinks:['powderhornfirearms.com','powderhornfirearms.com','waterauthority.orangecountygov.com/','waterauthority.orangecountygov.com/','','','','','herbs-plus.com','herbs-plus.com','hivethinking.org','hivethinking.org','www.ugsoa16.com/','','www.christmascoal.net/','www.christmascoal.net/'],
		autoScroll:false,
		scrollDir:'horizontal',
		scrollDuration:3,
		controlLocation:'left'
	});
}

function init_feedback(){
	
	var $feedback = $('#feedback');
	$feedback.dbdtextscroller({
		width:500,
		height:330,
		text:['Fantastic job on some tough javascripting! <br /><b>[g8z - Lakewood, US]</b>',
			 'Great coder, who is easy to get on with and quick to deliver regular updates and completed work on time and to an excellent standard	<br /><b>[britishboxing - Southgate, UK]</b>',
			 'DBD Sleighd was an excellent provider. They took my rough outline and sculpted it to exactly what I needed to get done. They were happy to explain the workings of the software, and were happy to change a couple of things that i was unsure about. All in all, I am very pleased with the work done, and will definitely use DBD Sleighd in the future. <br /><b>[bill.marcy - Pine City, US]</b>',
			 'The work was completed in a timely manner ahead of deadline and project communication was good. The worker was very patient and cooperative when working with us on the details of the webpage design. We were offered screenshots every step of the way, and that made it easy to develop the page into what we were looking for. The worker was available during testing for support and instant code correction when needed. Everyone involved with the project is pleased with the results and satisfied that all concerns and suggestions were addressed. The code is clean and easy to work with. We hope to work with DBD Sleighd again in the future. <br /><b>[WLC-NY - Circleville, US]</b>',
			 'Shannon was easy to work with, very nice and patient in getting the job done exactly as we requested. She was flexible and intuitive - she thought about how the site SHOULD function and what would be best. <br /><b>[New Christian Artist LLC - Cortland, US]</b>',
			 'Great Coder! got the work in 1/2 the time of what I asked. Great communication <br /><b>[APSoftware - St. Petersburg, US]</b>',
			 'Coder did a deep and complete testing. Results and suggestions are top. Report is clear. <br /><b>[Pixbyte - Berlin, Germany]</b>'],
		scrollDuration:5
	});

}
