function add_toggle(field) {
	$("#"+field).focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
 }

$(function(){
		$('#scrscr').jScrollPane();
		$('#scrscr-1').jScrollPane();
		$('#scrscr-2').jScrollPane();
		$('#skk').jScrollPane();});
		function port_stick(){port_init();sticky_nav(document.getElementById('btn_urunler'));}
function sticky_nav(element)
{
	$(".btns").children("li").each(function(count,ele){
		$(ele).children("a:first").css("background-position","left");
	});
	$(element).children("a:first").css("background-position","right");
}

function sticky_nav_urunler(element)
{
	$("#nav_port a").each(function(count,ele){
		$("#"+ele.id).removeClass('navbtn-selected');
	});
	$("#"+element).addClass('navbtn-selected');
}
function stick_nav(id)
{
	var classes = $("#"+id).attr("class");
	
	var tmp = new Array();
	
	tmp = classes.split(' ');
	
	for(i=0;i<tmp.length;i++)
	{
		if(tmp[i].substring(0,3) == "cat") 
		{
			cat = tmp[i].substring(3,tmp[i].length);
			if(!$("#"+cat).hasClass("navbtn-selected")) sticky_nav_urunler(cat);
		}
	}
	
}

function next_project()
{
	if($('#projects div.current').hasClass('last')) {
		stick_nav('project_0');
		to_project('project_0', 1200);
		}
	else {
		var new_id = new_proj_id('next');
		stick_nav(new_id);
		to_project(new_id, 600);		
		}
	return preventDefaultAction(e);

}

function previous_project()
{
	if($('#projects div.current').hasClass('first')) {
		stick_nav('project_1');
		to_project('project_1', 1200);
		}
	else {
		var new_id = new_proj_id('previous');
		stick_nav(new_id);
		to_project(new_id, 600);		
		}
	return preventDefaultAction(e);

}
/*
function previous_project(e) 
{
	if($('#projects div.current').hasClass('first')) {
		var last_id = get_last_project_id();
		stick_nav(last_id);
		to_project(last_id, 1200);	
		}
	else {
		var new_id = new_proj_id('previous');
		stick_nav(new_id);
		to_project(new_id, 600);
		}
	return preventDefaultAction(e);
	}*/

function get_last_project_id() {
	return $("#projects div.last").attr("id");
	}


function to_project(new_id, speed) 
{
	if(speed) {
		$("#projects").animate({
				left: 0-$('#' + new_id).position().left
				}, speed);
			set_current(new_id);
		}
	else {
		$("#projects").animate({
				left: 70-$('#' + new_id).position().left
				}, 600);
			set_current(new_id);
		}
}
function set_current(id) 
{
	$("#projects .current").removeClass('current');
	$('#' + id).addClass('current');
}

function new_proj_id(which) 
{
	current = $("#projects div.current").attr("id");
	
	if(which=='next')
		new_id = $("#projects div.current").next().attr("id");
	else
		new_id = $("#projects div.current").prev().attr("id");
//OLD CODE -- needed to change so that updates are easy
//	var num = current.substring(current.lastIndexOf('_') + 1, current.length);
//	if(which == 'next')
//		num++;
//	else
//		num--;
//	var new_id = 'project_' + num;
	return new_id;
}

function preventDefaultAction(e)	{
	if (e)	{
			if (typeof e.preventDefault != 'undefined')	{ 
			e.preventDefault(); 
			}               
		else	{ 
			e.returnValue = false; 
			}                   
			}
		// safey for handling DOM Level 0
		return false;
	}

//Created this for urunler page
function jump_to(cat)
{
	id = $("#projects div."+cat).attr("id");
	if(id != undefined) to_project(id, 600);
	
}

function port_init()
{
	if($("#has_loaded").attr("value") == "no")
	{
		$('#projects').load("projects.php",'',function(){
			

			var left = 775;
			$('#projects').children().each(function(child,aab){
				
				$(aab).css('left',left);
				left+=775;
				
			});
			$("#go_left").click(previous_project);
			$("#go_right").click(next_project);
			
			$('div.project_info, div.pi_background').fadeTo(5, 0);
			$('div.project_info, div.pi_background').show();
			
			
			$('div.project_info').hover(
				function() {
					$(this).stop(true,true).fadeTo('normal', 1); 
					$(this).siblings('div.pi_background').stop(true,true).fadeTo('normal', .93);
				},
				function() {
					$(this).fadeTo('normal', 0); 
					$(this).siblings('div.pi_background').fadeTo('normal', 0);
				}
			);
			
			$("#has_loaded").attr("value","yes");
			
			 if(typeof sIFR == "function"){
			
		            sIFR.replaceElement(named({sSelector:"h1.white",sFlashSrc:"swf/choc.swf",sColor:"#FFFFFF",sHoverColor:"#000000",sWmode:"transparent",sFlashVars:"offsetTop=0"}));	
		            sIFR.replaceElement(named({sSelector:"h2.red",sFlashSrc:"swf/choc.swf",sColor:"#c80208",sWmode:"transparent",sFlashVars:"offsetTop=0"}));
			 }
			 
			
		});
		
		
	}
	
	
	


}




