function homeHeader() {
	beforehtml = '<div id=\"headerbanner_nav\">';
	$('#headerbanner ul').before(beforehtml).cycle({ 
    fx:     'scrollHorz', 
    speed:  600,
    timeout: 8000,
    pager:  '#headerbanner_nav' 
	});
}

function screenshotInit() {
	$('#screenshots ul').cycle({
		fx: 'scrollLeft',
		speed: 300,
		timeout: 0,
    pager:  '#screenshot_nav',
    pagerAnchorBuilder: function(idx, slide) { 
			return '#screenshot_nav a:eq(' + idx + ')'; // return selector string for existing anchor 
    }
	});
	
	$('#screenshot_overlay_cover').click(function() { screenShotClose(); });
}

function featProject(pid) {
	$('#portfolio_featured li').hide();
	$('#portfolio_featured_nav li').removeClass('active');
	$('.portfeat_nav'+pid).addClass('active');
	$('#portfeat'+pid).fadeIn(200);

}

function portFilter(wtid,pg,leavehash) {
	if (typeof leavehash == 'undefined') location.hash = '';	
	portheight = $('#portfolio').height() + 27;
	$('#portfolio').addClass('loading').html('').css('height',portheight);
	$.ajax({
		url: "/inc/modules/portfolio/portfolio_ajax.php",
		global: false,
		type: "POST",
		data: "wtid=" + wtid + "&pg=" + pg,
		dataType: "html",
		success: function(msg) {
			$('#portfolio').css("height", 'auto').removeClass('loading').html(msg);
		}
	});

}

function portSelect(pid,testimonial) {
	$('#portfolio_overlay_cover, #portfolio_overlay').removeClass('notest').show();
	if (testimonial == 'false') $('#portfolio_overlay').addClass('notest');
	$('#portfolio_overlay').html('<div class="loading"></div>').show();
	
	$.ajax({
		url: "/inc/modules/portfolio/portfolio_ajax_item.php",
		global: false,
		type: "POST",
		dataType: "html",
		data: "pid=" + pid,
		success: function(result){
			$('#portfolio_overlay').html(result);
		}
	});
}

function portClose() {
	$('#portfolio_overlay_cover').hide();
	$('#portfolio_overlay').html('').removeClass('notest').hide();
}

function screenShotTour() {
	$('#screenshot_overlay_cover').show();
	$('#screenshot_overlay').show();
}

function screenShotClose() {
	$('#screenshot_overlay_cover').hide();
	$('#screenshot_overlay').hide();
}

function ajaxPost(formid, errmsg_id, success_id, success_file, errorcheck_file) {
	formdata = $('#'+formid).serialize();
	if (typeof errorcheck_file != 'undefined') formdata += "&errorcheck_file=" + errorcheck_file;
	$.ajax({
		url: "/inc/ajax/post.php",
		global: false,
		type: "POST",
		dataType: "html",
		data: formdata,
		success: function(result) {
			if (result.length == 0) { // Hit ajax success file
				$.ajax({
					type: 'POST',
					url: '/inc/ajax/' + success_file,
					data: formdata,
					dataType: "html",
					success: function(result) {
						$('#'+success_id).html(result);
					}
				});
			} else { // Set error message
				$('#'+errmsg_id).html(result);
			}
		}
	});
	
}

function initQtip(type) {
	if (type == 'site') {
		$('a.qtip[href][title]').qtip({
		content: {
			text: false // Use each elements title attribute
		},
		position: {
			corner: {
				tooltip: 'topLeft',
				target: 'bottomMiddle'
			}
		},
		style: {
			name: 'light',
			border: {
				width: 0,
				radius: 5,
				color: '#fff'
			},
			tip: true
		}
		});
	} else if (type == 'form') {
		//$('li.err input, li.err textarea').qtip('destroy');
		$('li.err[title]').qtip({
		content: {
			text: false // Use each elements title attribute
		},
		position: {
			corner: {
				tooltip: 'topLeft',
				target: 'bottomLeft'
			}
		},
		style: {
			name: 'red',
			background: '#c00',
			color: '#ffffff',
			border: {
				width: 0,
				radius: 5,
				color: '#c00'
			},
			tip: true
		}
		});
		//li.err label.checkbox_single[title], li.err label.checkbox_multiple[title]
	}
}

$(document).ready(function() {
	// All http links / rel="external" links open in a new window
	$('a[rel*=external]').click(function() {
		window.open(this.href);
		return false;
	});
	
	// Hide contact us tab on iPad
	if (navigator.platform == "iPad") {
		$('div#getintouch').css('display', 'none');
	}
	
	screenshotInit();
	
	$(document).pngFix(); 
	
	initQtip('site');

	$('#footer_social_email').click(function() {
		if ($(this).val() == 'Enter your email address...') $(this).val('');
	}).blur(function() {
		if ($(this).val() == '') $(this).val('Enter your email address...');
	});

	$('#footer_social_form').submit(function() {
		ajaxPost('footer_social_form','footer_social_err', 'footer_social_form_wrapper', 'newsletter_signup.php', 'newsletter_errorcheck.php'); return false;
	});
	$('#footer_social_go').click(function() {
		ajaxPost('footer_social_form','footer_social_err', 'footer_social_form_wrapper', 'newsletter_signup.php', 'newsletter_errorcheck.php'); return false;
	});
		
	$("a#getintouch_tab").click(function() {
		if ($("#getintouch").css('right') == '-559px') { targetmarg = '0'; } else {	targetmarg = '-559px'; }
		$("#getintouch").stop().animate({'right': targetmarg}, 'fast');
	});
	$('a#getintouch_close').click(function() {
		$("#getintouch").stop().animate({'right': '-559px'}, 'fast');
	});
	
/*
	$('#getintouch').tabSlideOut({
		tabHandle: '.getintouch_tab',                     //class of the element that will become your tab
		tabLocation: 'right',                      //side of screen where tab lives, top, right, bottom, or left
		speed: 300,                               //speed of animation
		action: 'click',                          //options: 'click' or 'hover', action to trigger animation
		topPos: '240',                          //position from the top/ use if tabLocation is left or right
		leftPos: '0',                          //position from left/ use if tabLocation is bottom or top
		fixedPosition: true                      //options: true makes it stick(fixed position) on scroll
	});*/
});
