/*
* abyss.js
* v.1.0
* Mike Jones
* 17th March 2009
* MartyJ Consultants Ltd
* http://martyj.co.uk
*/



$(document).ready(function(){
//alert(path_url);
//alert(base_url);
	$("#"+page).addClass('active');
	$("h1").each(function(){
		$(this).css("background-image","url("+base_url+"images/"+$(this).attr('id')+"_h1.png)");
	});
	$("#main_nav li").each(function(){
//alert("url(../images/nav_"+page+".png");		
		$(this).css("background-image","url("+base_url+"images/nav_"+$(this).attr('id')+".png)");
		//$(this).find("img[id*='active']").fadeOut('fast');
	
		if($(this).attr('class').indexOf('active')<0)
		{
			$(this).hover(
				function () {
				$(this).addClass('active');
				},  
	      		function () { 
				$(this).removeClass('active');      	
	     		} 
	    	); 
	    	$(this).click(function(){
	    		$("#main_nav li").removeClass('active');
	    		window.location.href = base_url+$(this).attr('id')+'.php';
	    	});

		}
		if($(this).is('#contact')) return false;
		//$(this).addClass('bulletted');
	});

	
	switch (page)
	{
		case 'index':

			$('#right_content').css(
				{
					'width':'55%',
					'background-image':'url(../images/Home.jpg)',
					'background-position':'0px 25px',
					'background-repeat':'no-repeat'
				});
			break;
		case 'services':
			//servicesList();
			$('#right_content').css(
				{
					'width':'50%',
					'background-image':'url(../images/Services.jpg)',
					'background-position':'0px 175px',
					'background-repeat':'no-repeat'
				});
			break;
		case 'clients':
			//$('#clientlist').columnizeList({cols:2,constrainWidth:0});
			clientList();
			showClientImage(0);
			break;
		case 'portfolio':
			$('#wrapper').css('height','690px');
			portfolioList();
			showFolio('first',true);
			break;
		case 'contact':
			$('#left_content').css(
				{
					'width':'45%',
					'height':'450px',
					'background-image':'url(../images/Contact.jpg)',
					'background-position':'100px -10px',
					'background-repeat':'no-repeat'
				});

			break;
	} // end page switch

}) // end of document ready function

/*
function pageActive(page)
{
	$("#"+page).addClass('active');
}
*/

function servicesList()
{
	//alert('in func');
	$("#serviceslist li").each(function(){
		//alert('in each');
		$(this).hover(
				function () {
					//alert('over');
					$(this).addClass('over');
	      		},  
	      		function () { 
					//alert('out');
					if($(this).attr('class').indexOf('selected')<0)
					{
						$(this).removeClass('over');
					}
	     		} 
	    	);
	    	
	    $(this).click(function(){
	    	$("#serviceslist li").removeClass('selected').removeClass('over');
	    	$(this).addClass('selected');
			var service_params = {'get_service':$(this).attr('id')};
			$.ajax({
				type:'POST',
				url:base_url+'services.php', //?get_service='+$(this).attr('id') - alternative without data and type='GET'
				data:{'params':JSON.stringify(service_params)},
				dataType:'html',
				success:function(returndata){
						$("#left_content").html(returndata);
					}
				});

			

	    });	 

	});
} // end of function serviceslist

function clientList()
{
	//alert('in func');
	$(".clientlist li").each(function(){
		//alert('in each');
		$(this).hover(
				function () {
					//alert('over');
					$(this).addClass('over');
	      		},  
	      		function () { 
					//alert('out');
					if($(this).attr('class').indexOf('selected')<0)
					{
						$(this).removeClass('over');
					}
	     		} 
	    	);
	    	
	    $(this).click(function(){
	    	$(".clientlist li").removeClass('selected').removeClass('over');
	    	$(this).addClass('selected');
	    	showClientImage($(this).attr('value'));
	    });	 
	});
} // end of function clientList

function showClientImage(clientIdx)
{
	
	//alert(clientIdx);	
	$("#clientname").text(clients[clientIdx]['name']);
	$("#client_image").attr({src: "images/clients/"+clients[clientIdx]['image']});
	$("#clienttext").text(clients[clientIdx]['text']);
	$("#clienturl").attr({href:'http://'+clients[clientIdx]['url']}).text(clients[clientIdx]['url']);
}

function portfolioList()
{
	$("li.live").each(function(){
		$(this).hover(
			function(){
				$(this).css('color','#b1b3b4');
				
			},
			function(){
				$(this).css('color','#000000');
				
				
			}
		);
		$(this).click(function(){
			showFolio($(this).attr('id'));
		});
	});	
}

function showFolio(clientID,start)
{
	start = start==null?false:true;
	//alert(clientID);	
	var folio_params = {'get_folio':clientID};
	$.ajax({
		type:'POST',
		url:base_url+'portfolio.php', //?get_portfolio='+clientID - alternative without data and type='GET'
		data:{'params':JSON.stringify(folio_params)},
		dataType:'html',
		success:function(returndata){
				if(start)
				{
					$("#folios").scrollTo($('li.show'),0,{axis:'x',offset:0});
					$("#folios li.show").html(returndata);
				}
				else
				{
					$("#folios li.show").removeClass('show').addClass('temp');
					$("#folios li.noshow").html(returndata).toggleClass('show').toggleClass('noshow');
					$("#folios li.temp").addClass('noshow').removeClass('temp');
					
					scrollIt();
				}

				
				$("li[class='show'] img.thumb")
						.each(function(){
							$(this).height(80);
						})
						.mouseover(function(){
				
						var par = $(this).parent().get(0);
						//alert($(par).attr('id'));
						if($(par).attr('id')=='folioMainPic') return false;
						//console.log($(this).attr('src'));
						var thumbName = $(this).attr('src');
						var thumbParts = thumbName.split('_');
						var newSrc = thumbParts[0]+'.png';//_'+thumbParts[1]+'_'+thumbParts[2]+'.jpg';
						//console.log(newSrc);
						var mainImage = $(this).parents('li').find('img:eq(0)');
						//console.log(mainImage.attr('src'));
						mainImage.attr('src',newSrc);
						
				
				});
			}
		});
}

function scrollIt()
{
	$("#folios").scrollTo($('li.show'),1000,{axis:'x',offset:0});
}

