function manageportfolio(index,left,right)
{
	var portfoliohtml = '<div class="gallery-container" id="container'+index+'">';
		//portfoliohtml += '<div id="blank" style="width:180px; height:406px ; float:left;"> </div>';
		portfoliohtml +='<div id="screenshot'+index+'" style="width:632px;height:406px;margin:0 auto;">';
		if(left==true)
			{
	
				portfoliohtml +='<div class="prevarrowportfolio">';
				portfoliohtml +='<img onmouseout="this.src='+"'"+BASEPATH+'images/previous.jpg'+"'"+'" onmouseover="this.src='+"'"+BASEPATH+'images/mo_previous.jpg'+"'"+'" onclick="javasript:left()"src="'+BASEPATH+'images/previous.jpg" /></div>';
	
			}
			if(left == false)
			{
				portfoliohtml +='<div class="prevarrowportfolio"></div>';
			}
			if(right==true)
			{
				portfoliohtml +='<div class="nextarrowportfolio">';
	
				portfoliohtml +='<img onmouseout="this.src='+"'"+BASEPATH+'images/next.jpg'+"'"+'" onmouseover="this.src='+"'"+BASEPATH+'images/mo_next.jpg'+"'"+'" onclick="javasript:right()"src="'+BASEPATH+'/images/next.jpg" /></div>';
			}
			if(right==false)
			{
				portfoliohtml +='<div class="nextarrowportfolio"></div>';
			}
		portfoliohtml +='<div style="width:632px;height:406px;border: 5px solid #ffffff; margin-left:-5px;@margin-left:0px">';
		portfoliohtml +='<div id="s'+ index + '" class="pics"></div>';
		portfoliohtml +='</div>';
		
		portfoliohtml +='<div style="width:642px;margin-top:10px;">';
		
		
			portfoliohtml +='<div class="mouse" style=" float:right;z-index:50; margin-top:-5px;width:30px; height:20px;">';
			
			portfoliohtml +='<img onmouseout="this.src=' + "'" + BASEPATH+'images/left.jpg'+"'" + '" onmouseover="this.src=' + "'" + BASEPATH+'images/mo_left.jpg' + "'" + '" id="left'+index+'" src="'+ BASEPATH+ 'images/left.jpg"/>';
		
			portfoliohtml +='<img onmouseout="this.src=' + "'" + BASEPATH+'images/right.jpg'+"'" + '" onmouseover="this.src=' + "'" + BASEPATH+'images/mo_right.jpg' + "'" + '" id="right'+index+'" src="'+ BASEPATH+ 'images/right.jpg"/>';
			
			portfoliohtml +='</div>';
		
		
		portfoliohtml +='<div class="nav" id="nav'+ index + '"  style="float:right;margin-right:5px;"></div>';
		
		portfoliohtml +='<div id="projectInfo'+ index +'" style="float:left;width:300px; margin-left:-5px;@margin-left:0px;"></div>';
		portfoliohtml +='</div>'; // end projectinfo+nav+arrow
		
		
		portfoliohtml +='</div>';//endscreenshoot
		portfoliohtml +='</div>';//end gallery-container
			
	
	return portfoliohtml;
	
}
function addElement(type,id,size,divname) 
	{
	
 	var d = document.createElement("div");
 	var apu = document.createElement("input");
	apu.setAttribute("type", type);
	apu.setAttribute("class", "temp");
 	apu.setAttribute("name",id+"[]");
	apu.setAttribute("id", id+"[]");
	apu.setAttribute("size",size);
 	apu.setAttribute("maxlength",100);
	d.appendChild(apu);
 	document.getElementById(divname).appendChild(d);
	}

//Add an item as favorite of user
function getProjectImage(ID)
{
	$.ajax({
	  type: "POST",
	  dataType: "json",
	  url: BASEPATH + "portfolio/getProjectImage/" + ID,
	  success: function(data){
		  
		ImageDataAll = new Array();	
		$.each(data.imageItems, function(i,item){ ImageDataAll.push(item) });  
		if(!ImageDataAll[1])
		{
			$("#screenshot"+ID +" div.mouse").hide();
		}
	    $("#s"+ID).html(ImageDataAll[0]);
		
		 $(function() {
        	$("#s"+ID +" a.thick").lightBox();
    	});
		$("#s"+ID).cycle({
				fx:     'fade',
				speed:  'fast',
				timeout: 0,
				pager:  '#nav'+ID,
				next: '#right'+ID,
				next2: "#s" + ID + ' .slide',
				prev: '#left'+ID
			});
	  }
	});
}
function getProjectData(ID)
{
	$.ajax({
	  type: "POST",
	  url: BASEPATH + "portfolio/projectData/" + ID,
	  success: function(data){
	    $("#projectInfo"+ID).html(data);
		
	  }
	});
}

function getRecentProjectId()
{
	$.ajax({
	  type: "POST",
	  dataType: "json",
	  url: BASEPATH + "home/recent_projects",
	  success: showArchive
	});
}


function getProjectIdByMonthYear(year,month)
{
	$.ajax({
	  type: "POST",
	  dataType: "json",
	  url: BASEPATH + "archives/archive_projects/" + year + "/" + month,
	  success: showArchive
	});
}
function getProjectIdByTypes(type)
{
	$.ajax({
	  type: "POST",
	  dataType: "json",
	  async: false,
	  url: BASEPATH + "portfolio/getProjectIdByTypes/" + type,
	  success:showArchive
	});
}
function setImageOrder(workid, data ,hash)
{
	$.ajax({
			  type: "POST",
			  url: BASEPATH + "admin/projects/setimageorder/"+workid,
			  data: data,
			  //async: false,
			  success: function(msg){
				if(msg == 'yes')
				{
					document.forms.form1.submit();
				}
				else
				{
					alert('Sorry!');
				}
			  }
	  });
}
function showArchive(data)
{
	archiveProjects = new Array();	
	$.each(data.items, function(i,item){ archiveProjects.push(item) });
	$('#galery2').css("width",documentwidth * archiveProjects.length+'px');
	
	$("#galery2").html('');
		
	if(archiveProjects.length >0)
	{
		$("#work_category").append('<div id="projectsNumber" style="float:right; text-align:right; padding-right:3px;padding-top:5px">'+'1 of '+archiveProjects.length+'</div>');

		for(var i=0;i<archiveProjects.length;i++)
		{
			var output = manageportfolio(archiveProjects[i],(i==0)? false : true,(i==(archiveProjects.length-1))? false : true);
			
			$("#galery2").append(output);
			
			$("#container"+archiveProjects[i]).css("width",(100/archiveProjects.length)+"%");
			getProjectImage(archiveProjects[i]);
			getProjectData(archiveProjects[i]);
		}
		
		$('.gallery-container').css("width",documentwidth + "px");
	}
	else
	{
		
		var emptyportfoliohtml = '<div style="width:'+ documentwidth +'px;float:left">';
			emptyportfoliohtml +='<div id="screenshot" style="width:632px;height:406px;border: 5px solid #ffffff; margin:0 auto;"><p style="padding:200px 0px 0px 240px"> No Projects are Available..</p>';
			emptyportfoliohtml +='</div> <div id="projectInfo" style="float:left; height:100px;width:300px"><br /></div></div>';
		$("#galery2").html('');
		$("#galery2").append(emptyportfoliohtml);
	}
	
}