var DHTML_SUITE_THEME_FOLDER = "includes/core/dhtml-suite-batur/themes/";
var DHTML_SUITE_THEME = 'blue';

function funInclude(txtFile)
{
	document.write('<'+'script');
	document.write(' language="javascript"');
	document.write(' type="text/javascript"');
	document.write(' src="'+txtFile+'">');
	document.write('</'+'script'+'>');
}

//funInclude('includes/core/dhtml-suite-batur/js/ajax.js');
//funInclude('includes/core/dhtml-suite-batur/js/separateFiles/dhtmlSuite-common.js');
//funInclude('includes/core/dhtml-suite-batur/js/separateFiles/dhtmlSuite-ajaxUtil.js');
//funInclude('includes/core/dhtml-suite-batur/js/separateFiles/dhtmlSuite-imageEnlarger.js');
//funInclude('includes/core/dhtml-suite-batur/js/separateFiles/dhtmlSuite-dynamicContent.js');
//funInclude('includes/core/dhtml-suite-batur/js/separateFiles/dhtmlSuite-modalMessage.js');

//var enlargerObj = '';

$(document).ready(function() {
	try
	{
		funPerPageLoad();
	}
	catch(err)
	{
	}
	
	preloader();
	
	funInitiateHomeRolling();
	funThumbs();
});



var intProductImage = 0;

function funProductImageSwap(num)
{
	var divRef1 = document.getElementById('product-image-'+num);
	var divRefThumb1 = document.getElementById('product-thumb-'+num);
	var divRef2 = document.getElementById('product-image-'+intProductImage);
	var divRefThumb2 = document.getElementById('product-thumb-'+intProductImage);
	
	divRef1.style.display = '';
	divRefThumb1.style.display = 'none';
	divRef2.style.display = 'none';
	divRefThumb2.style.display = 'inline';
	
	intProductImage = num;
}

function funProductImageLarge(imagePath,title,description)
{
	enlargerObj.displayImage(imagePath,title,description);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var OptionWindow = window.open(theURL,winName,features);
  OptionWindow.focus();
}

function funShowGallery()
{
	var divRef = document.getElementById('gallery-area-backing');
	var divRef2 = document.getElementById('gallery-area');
	
	divRef.style.opacity = 0;
    divRef.style.MozOpacity = 0;
    divRef.style.filter = "alpha(opacity=0)";
    divRef.style.display = '';
    divRef.style.position = 'absolute';
    divRef.style.top = 0+'px';
    divRef.style.left = 0+'px';
    divRef.style.zIndex = 90000;
    divRef.style.width = funGetBrowserWidth() + 'px';
    if (document.body.clientHeight + 50 < funGetBrowserHeight)
    	divRef.style.height = document.body.clientHeight + 50 + 'px';
    else
    	divRef.style.height = '3000px';
    
    divRef2.style.zIndex = 90001;
    divRef2.style.display = '';
    funPositionCenter(divRef2.id);
   	divRef2.style.display = 'none';
    
   	funFadeIn('gallery-area-backing',0,5,10,'document.getElementById(\'gallery-area\').style.display=""; funPositionCenter(\'gallery-area\');');
}

function funHideGallery()
{
	var divRef = document.getElementById('gallery-area-backing');
	var divRef2 = document.getElementById('gallery-area');
	divRef.style.opacity = 1;
    divRef.style.MozOpacity = 1;
    divRef.style.filter = "alpha(opacity=100)";
    divRef.style.display = '';
    divRef.style.position = 'absolute';
    divRef.style.top = 0+'px';
    divRef.style.left = 0+'px';
    divRef.style.zIndex = 100000;
    divRef.style.width = funGetBrowserWidth() + 'px';
    divRef.style.height = document.body.clientHeight + 50 + 'px';
    
    divRef2.style.zIndex = 100001;
    divRef2.style.display = 'none';
    
   	funFadeOut('gallery-area-backing',80,5,10,'document.getElementById(\'gallery-area-backing\').style.display="none";');
}

function funFadeIn(id,opacity,fadeStep,fadeSpeed,callOnFinish)
{
	var i = 0;
	var a = 0;
	var multiplier = (document.all ? 2 : 1);
	
	var divRef = document.getElementById(id);
	callOnFinish = unescape(callOnFinish);
	
	divRef.style.opacity = (opacity / 100);
    divRef.style.MozOpacity = (opacity / 100);
    divRef.style.filter = "alpha(opacity=" + opacity + ")";
    
    opacity += (fadeStep * multiplier);
	
	if (opacity >= 100)
	{
		divRef.style.opacity = (opacity / 100);
	    divRef.style.MozOpacity = (opacity / 100);
	    divRef.style.filter = "alpha(opacity=" + opacity + ")";
		if (callOnFinish)
			eval(callOnFinish);
	}
	else
	{
		setTimeout('funFadeIn(\'' + id + '\','+ opacity +','+fadeStep+','+fadeSpeed+',\''+escape(callOnFinish)+'\')',(fadeSpeed / multiplier));
	}
}

function funFadeOut(id,opacity,fadeStep,fadeSpeed,callOnFinish)
{
	var i = 0;
	var a = 0;
	var multiplier = (document.all ? 2 : 1);
	
	var divRef = document.getElementById(id);
	callOnFinish = unescape(callOnFinish);
	
	divRef.style.opacity = (opacity / 100);
    divRef.style.MozOpacity = (opacity / 100);
    divRef.style.filter = "alpha(opacity=" + opacity + ")";
    
    opacity -= (fadeStep * multiplier);
	
	if (opacity <= 1)
	{
		if (callOnFinish)
			eval(callOnFinish);
	}
	else
	{
		setTimeout('funFadeOut(\'' + id + '\','+ opacity +','+fadeStep+','+fadeSpeed+',\''+escape(callOnFinish)+'\')',(fadeSpeed / multiplier));
	}
}

function funGetBrowserWidth()
{
	if(self.innerWidth)
		return self.innerWidth;
	
	return document.documentElement.offsetWidth;
}
	
function funGetBrowserHeight()
{
	if(self.innerHeight)
		return self.innerHeight;
	
	return document.documentElement.offsetHeight;
}

function funPositionCenter(id)
{
	var divRef = document.getElementById(id);
	
	divRef.style.position = 'absolute';
	
	var browserHeight = funGetBrowserHeight();
	var browserWidth = funGetBrowserWidth();
	var browserOffsetTop = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	var browserOffsetLeft = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
	
	intTop = ((browserHeight - divRef.offsetHeight)/2)+browserOffsetTop;
	if (intTop < 0)
		intTop=0;
	if (browserOffsetTop > intTop)
		intTop = browserOffsetTop;
	
	intLeft = ((browserWidth - divRef.offsetWidth)/2)+browserOffsetLeft;
	if (intLeft < 0)
		intLeft=0;
	
	divRef.style.top = intTop+'px';
	divRef.style.left =  intLeft+ 'px';
}

function preloader() 
{
    // counter
    var i = 0;

    // create object
    imageObj = new Array;

	 
	 // set image list
    images = new Array();
	images[0]=txtBaseURL+"images/top_nav_over.png";
	images[1]=txtBaseURL+"images/top_nav_over_left.png";
	images[2]=txtBaseURL+"images/prod-drop-over.png";
	images[3]=txtBaseURL+"images/product_home_nav_over.png";
	images[4]=txtBaseURL+"images/quote-plane-over.png";
	images[5]=txtBaseURL+"images/rolling_nav_over.png";
	images[6]=txtBaseURL+"images/nav_bk_over.png";
	images[7]=txtBaseURL+"images/icon_environmental_over.png";
	images[8]=txtBaseURL+"images/icon_service_over.png";
	images[9]=txtBaseURL+"images/icon-team-over.png";
	images[10]=txtBaseURL+"images/jump-list-base.png-over.png";
	images[11]=txtBaseURL+"images/jump-list-over.png";
	images[12]=txtBaseURL+"images/icon-map-over.png";
	images[13]=txtBaseURL+"images/icon-newsletter-over.png";
	images[14]=txtBaseURL+"images/button_over.png";
	images[15]=txtBaseURL+"images/button-cancel-over.png";
	images[16]=txtBaseURL+"images/arrow-close-over.png";
	images[17]=txtBaseURL+"images/arrow-list-over.png";
	images[18]=txtBaseURL+"images/arrow-up-over.jpg";
	
	// start preloading
	for(i=0; i<images.length; i++) 
	{
		imageObj[i] = new Image();
		imageObj[i].src=images[i];
	}
} 

window.onresize = function() {
	if (document.getElementById('gallery-area-backing'))
	{
		if (document.getElementById('gallery-area').style.display == '')
		{
			var divRef = document.getElementById('gallery-area-backing');
		
			divRef.style.position = 'absolute';
	    	divRef.style.top = 0+'px';
		    divRef.style.left = 0+'px';
	    	divRef.style.width = funGetBrowserWidth() + 'px';
		    divRef.style.height = document.body.clientHeight + 50 + 'px';
		    
	    	funPositionCenter('gallery-area');
		}
	}
}

function displayMessage(url)
{	
	messageObj.setSource(url);
	messageObj.setCssClassMessageBox(false);
	messageObj.setSize(500,300);
	messageObj.setShadowDivVisible(true);	// Enable shadow for these boxes
	messageObj.display();
}

function displayMessageIframe(url,width,height)
{	
	messageObj.setHtmlContent('<iframe src="' + url + '" width="' + width + '" height="' + height + '" frameborder="0"></iframe>');
	messageObj.setSize(width,height);
	messageObj.setShadowDivVisible(true);
	messageObj.display();
}

function closeMessage()
{
	messageObj.close();	
}

function aboutMessage(url)
{
	MM_openBrWindow(url,'aboutWin','width=950, height=150, scrollbars=yes');
}

function funAddToCart(name)
{
	var frmRef=document.getElementById(name);
	var params = "method=xml"
	var txtSep = "&"
	
	for (i=0;i<frmRef.elements.length;i++)
	{
		ename = frmRef.elements[i].name;
		
		if (frmRef.elements[i].type.toLowerCase() == 'checkbox' )
		{
			if (frmRef.elements[i].checked)
				params = params + txtSep + ename + '=' + funURLEncode(frmRef.elements[i].value);
			else
				continue;
		}
		else if (frmRef.elements[i].type.toLowerCase() == 'radio' )
		{
			if (frmRef.elements[i].checked)
				params = params + txtSep + ename + '=' + funURLEncode(frmRef.elements[i].value);
		}
		else
		{
			params = params + txtSep + ename + '=' + funURLEncode(frmRef.elements[i].value);
		}
		txtSep = "&";
	}
	objAjax.sendRequest('cart.php',params,'funAddToCartResponse');
}

function funAddToCartResponse(obj)
{
	try
	{
		var xmlDoc = obj.responseXML.documentElement;
	}
	catch(err)
	{
		alert('There was an error adding the item to the cart');
	}
	
	var ErrorMessage = "";
	var Services="";
	var CartLineID = "";
	
	if (xmlDoc.getElementsByTagName('ErrorMessage').length > 0)
	{
		if (xmlDoc.getElementsByTagName('ErrorMessage')[0].childNodes.length > 0)
			ErrorMessage = xmlDoc.getElementsByTagName('ErrorMessage')[0].childNodes[0].nodeValue;
	}
	if (xmlDoc.getElementsByTagName('CartLineID').length > 0)
	{
		if (xmlDoc.getElementsByTagName('CartLineID')[0].childNodes.length > 0)
			var CartLineID = xmlDoc.getElementsByTagName('CartLineID')[0].childNodes[0].nodeValue;
	}
	if (xmlDoc.getElementsByTagName('Services').length > 0)
	{
		if (xmlDoc.getElementsByTagName('Services')[0].childNodes.length > 0)
			var Services = xmlDoc.getElementsByTagName('Services')[0].childNodes[0].nodeValue;
		
		if (Services == 1)
			Services = true;
		else
			Services = false;
	}
	
	if (ErrorMessage == "" && CartLineID == "")
	{
		alert('There was an error processing your request');
	}
	else if (ErrorMessage == "")
	{
		if (Services)
			displayMessageIframe('includes/site/product-options.php?PostCart=1&CartLineID=' + CartLineID,520,420);
		else
			window.location.reload();
	}
	else
	{
		alert(ErrorMessage);
	}
}

function funURLEncode(txtValue)
{
	txtValue = encodeURIComponent(txtValue);
	
	return txtValue;
}

function funShowPopup(id)
{
	$('#horizon-container')
		.css('opacity',1)
		.css('position','absolute')
		.css('top',0)
		.css('left',0)
		.css('width',$(document).width())
		.css('height',$(document).height());
	
	$('#'+id).show();
	funPositionCenter(id);
	$('#'+id).hide();
	
	$('#horizon-container').fadeIn(800,function(){
		$('#'+id).show();
		funPositionCenter(id);
	});
	
	$(window).scroll(function(){funPositionCenter(id);});
	$(window).resize(function(){funPositionCenter(id);});
}

function funHidePopup(id)
{
	$('#'+id).hide();
	
	$('#horizon-container').fadeOut(800);
	
	$(window).scroll(function(){});
	$(window).resize(function(){});
}

var intHomeRollingCurrent = 0;
var refHomeRollingTimer = null;

function funInitiateHomeRolling()
{
	if (document.getElementById('home-rolling'))
	{
		refHomeRollingTimer = setTimeout('funHomeRollingNext()',7000);
	}
}

function funHomeRollingNext()
{
	clearTimeout(refHomeRollingTimer);
	
	var intCount = $('#home-rolling .image').length;
	var intNext = intHomeRollingCurrent+1;
	
	if (intNext >= intCount)
		intNext = 0;
	
	$('#rolling-image-' + intHomeRollingCurrent).fadeOut(800);
	$('#rolling-image-' + intNext).fadeIn(800);
	
	$('.rolling-nav-' + intHomeRollingCurrent).attr('id','');
	$('.rolling-nav-' + intNext).attr('id','rolling-active');
	
	intHomeRollingCurrent = intNext;
	
	refHomeRollingTimer = setTimeout('funHomeRollingNext()',5000);
}

function funHomeRolling(intNext)
{
	if (intNext == intHomeRollingCurrent)
		return false;
	
	clearTimeout(refHomeRollingTimer);
	
	$('#rolling-image-' + intHomeRollingCurrent).fadeOut(800);
	$('#rolling-image-' + intNext).fadeIn(800);
	
	$('.rolling-nav-' + intHomeRollingCurrent).attr('id','');
	$('.rolling-nav-' + intNext).attr('id','rolling-active');
	
	intHomeRollingCurrent = intNext;
	
	refHomeRollingTimer = setTimeout('funHomeRollingNext()',5000);
}

function funThumbs()
{
	$('.content-portfolio a').each(function(){
		$(this).css('position','relative').css('overflow','hidden');
		//$('span',this).css('visibility','visible').css('opacity',0);
		$(this).mouseenter(function(){
			$('span',this).fadeIn(400);
		});
		$(this).mouseleave(function(){
			$('span',this).fadeOut(400);
		});
	});
}

function funPortfolioPopup(txtHref)
{
	$('#popup-dynamic-content').html('');
	$('#popup-dynamic-content').load(txtHref + '?_popup=1');
	funShowPopup('popup-dynamic');
}

function funWorkCheckbox(refCheckbox)
{
	blnNoneChecked = false;
	
	if (refCheckbox.name == '_everything' && refCheckbox.checked)
	{
		$('#frmWorkType input[type=checkbox]').each(function(){
			if ($(this).attr('name') != '_everything')
				this.checked = false;
		});
	}
	else if (refCheckbox.name != '_everything')
	{
		$('#frmWorkType input[type=checkbox]').each(function(){
			if ($(this).attr('name') == '_everything')
				this.checked = false;
		});
	}
	
	if ($('#frmWorkType input[type=checkbox]:checked').length < 1)
	{
		$('#frmWorkType input[type=checkbox]').each(function(){
			if ($(this).attr('name') == '_everything')
				this.checked = true;
		});
	}
	
	funUpdateWorkService();
	funUpdateWork(false);
}

function funUpdateWorkService()
{
	$('#frmWorkServiceUpdate').html('Loading.....');
	$('#frmWorkServiceUpdate').load(txtBaseURL + 'our-work.php?_service=1&' + $('#frmWorkType').serialize());
}

function funUpdateWork(blnIncludeService)
{
	txtQuery = 'our-work.php?_portfolio=1&' + $('#frmWorkType').serialize();
	if (blnIncludeService)
		txtQuery += '&' + $('#frmWorkService').serialize();
	$('#portfolio-update').load(txtBaseURL +  txtQuery,function(){funThumbs()});
}
