var pSlide = 0, nIdx = 0;
function ContactUs()
{
	var n = iutils.get('form_name').value, e = iutils.get('form_email').value, s = iutils.get('form_subject').value, m = iutils.get('form_message').value;
	
	if (n == '' || e == '' || s == '' || m == '') 
	{ 
		alert('Please complete all fields'); 
		return; 
	}
	
	var cb = function()
	{
		iutils.get('form_name').value = '';
		iutils.get('form_email').value = '';
		iutils.get('form_subject').value = '';
		iutils.get('form_message').value = '';
	
		alert('Your message has been sent         \n\nThank You');
	}
	var request = 'action=contact&name=' + escape(n) + '&email=' + escape(e) + '&subject=' + escape(s) + '&message=' + escape(m);
	iutils.axcall('post.php',request,'null','post',cb)
//	alert(request);
}


function ViewSolution(id)
{
	$('#solution'+id).show();
	$('#solutions').fadeIn('fast');
}

function HideSolution(id)
{
	$('#solutions').fadeOut('fast', function() { $('#solution'+id).hide()});
}

function internalAttach()
{
	jQuery.each($('.col-2 img'), function()
	{
		var h = $(this).attr('hover');
		if (typeof h == 'string' && h.length)
		{
			var a = $(this).attr('hover');
			var b = $(this).attr('src');
			
			$(this).attr('ohover',a);
			$(this).attr('osrc',b);
				
			$(this).bind('mouseover', function()
			{
				var a = $(this).attr('ohover');
				$(this).attr('src',a);
			});
			$(this).bind('mouseout', function()
			{
				var a = $(this).attr('osrc');
				var i = parseInt($(this).attr('idx'));
				if (i == nIdx) return;
				$(this).attr('src',a);
			});
			
			$(this).bind('click', function() { aNav('index', $(this).attr('idx')); });
		}
	});
}

function mainSlider(iIdx)
{
	// check request
	var ssl = 0;
	if (iIdx != null)
	{
		ssl = iIdx;
	}
	else
	{
		var lc = window.location.href;
		if (lc.indexOf('#preview') != -1)
		{
			var pts = lc.split('#preview');
			var i = parseInt(pts[(pts.length-1)]);
			if (i > 0 && i < 9)
			ssl = i;
		}
	}
	$('#inw-'+ssl).fadeIn(1000, function() {
	
	  $('#preview').cycle({
		fx: 'fade',
		delay:0,
		speed: 1000,
		sync: 1, 
		continuous:0,
		cleartypeNoBg: true,
		cleartype: true,
		pauseOnPagerHover: true,
		pause: true,
		height:        '453px',
		autostop: true,
		autostopCount : 10,
		timeout: 0,
		startingSlide: ssl,
		before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
			var p = parseInt($(currSlideElement).attr('idx'))
			var n = parseInt($(nextSlideElement).attr('idx'))
			nIdx = n;
			if (p > 0)
			{
				$('#tmb-'+p).attr('hover',$('#tmb-'+p).attr('ohover'));
				$('#tmb-'+p).attr('src',$('#tmb-'+p).attr('osrc'));
			}
			if (n > 0)
			{
				var a = $('#tmb-'+n).attr('ohover');
				var b = $('#tmb-'+n).attr('osrc');
				$('#tmb-'+n).attr('hover',b);
				$('#tmb-'+n).attr('src',a);
			}
		}
	  });
	});
	mainAttach(ssl);

}
function mainAttach(idx)
{
	jQuery.each($('.col-2 img'), function()
	{
		var h = $(this).attr('hover');
		if (typeof h == 'string' && h.length)
		{
			var a = $(this).attr('hover');
			var b = $(this).attr('src');
			
			$(this).attr('ohover',a);
			$(this).attr('osrc',b);
				
			$(this).bind('mouseover', function()
			{
				var a = $(this).attr('ohover');
				$(this).attr('src',a);
			});
			$(this).bind('mouseout', function()
			{
				var a = $(this).attr('osrc');
				var i = parseInt($(this).attr('idx'));
				if (i == nIdx) return;
				$(this).attr('src',a);
			});
		}
	});
	if (idx > 0)
	{
		nIdx = idx;
		var a = $('#tmb-'+idx).attr('ohover');
		var b = $('#tmb-'+idx).attr('osrc');
		$('#tmb-'+idx).attr('hover',b);
		$('#tmb-'+idx).attr('src',a);
	}
}

var pNav = '', iNav = 0, iIdx = 0;
var pTiles = [];
pTiles['contact'] = 'Contact';
pTiles['about'] = 'About';
pTiles['solutions'] = 'Solutions';

function aNav(s, iIdx)
{
	if (iNav) return;
	iNav = 1;
	pNav = s;
	if (!iIdx) iIdx = 0;
	nIdx = 0;
	
	var cb = function()
	{
		iNav = 0;
		$('.col_').removeClass('ccurr_');
		$('#spell-'+pNav).addClass('ccurr_');

		document.title = (pTiles[pNav]) ? 'BolotoGroup - ' + pTiles[pNav] : 'BolotoGroup';
		if (pNav == 'index')
		{
			mainSlider(iIdx);
		}
		else if (pNav == 'about' || pNav == 'contact')
		{
			internalAttach();
		}
	}
	
	iutils.axcall('html/'+s+'.inc.php','','interrior','get',cb)
	
	return false;
}