/*
 * jQuery moveFlash
 * 
 * Version 1.0  (2010/05/03)
 * @requires jQuery v1.3.2 or above
 *
 * Examples at: http://wwww.savelearn.com
 * Copyright (c) 2010 SaveLearn
 * Http://www.savelearn.com
 */

(function($) {
	var tempwho=0;
	var one=0;
	var two=1;
	var three=2;
	var t;
	var sl_timel=500;
	var sl_timec=6000;
	var sl_lr="left";
	$.fn.moveflash =  function(
	timel,timec,lorr
	) {
	if (!isNaN(timel)) {
		sl_timel=timel;
	}
	if (!isNaN(timec)) {
		sl_timec=timec;
	}
	if (lorr=="left") {
		sl_lr="left";
	}else{
		sl_lr="right";
	}
		jQuery.getJSON("/web/get.php?action=flashmove",null,function(data){
			var continents = data.jobs;
			for(var i=0;i<continents.length;i++){
				var jqimg = jQuery("<img>").attr("src",continents[i].src);
				jqimg.attr("title",continents[i].title);
				var jqlink= jQuery("<a>").attr("href",continents[i].url);
				jqlink.attr("target","_blank");
				jqlink.append(jqimg);
				var jqdiv = jQuery("<div class=\"pic"+i+"\">");
				jqdiv.append(jqlink);
				$("#moveflash").append(jqdiv);
				//alert(continents[i].title);
			} 
			tempwho = 0;
	    });
		
		
		
    	$(this).find("#leftbut").click(function(){
    		animatego("left");
    		tempwho=num(tempwho-1);
    		//alert(tempwho);
    	});
    	$(this).find("#rightbut").click(function(){
    		animatego("right");
    		tempwho=num(tempwho+1);
    	});
    	
    	setTimeout(function(){
    		autogoto();
    	}, sl_timec);
    	
	};
	
	function autogoto()
	{
		if (sl_lr=="left") {
			animatego("left");
			tempwho=num(tempwho-1);
		}else{
			animatego("right");
			tempwho=num(tempwho+1);
		}
		setTimeout(function(){
    		autogoto();
    	}, sl_timec);
	}
	function animatego(lr)
	{
		if (lr=="left") {
		var temptwo;
		var tempthree;
			if (tempwho==0) {
				temptwo=1;
				tempthree=2;
			}
			if (tempwho==2) {
				temptwo=0;
				tempthree=1;
			}
			if (tempwho==1) {
				temptwo=2;
				tempthree=0;
			}
		
		$(".pic"+tempwho).animate({
			top: "60px",
			left: "55px", 
			width: "200px", 
			height:"100px"
		},sl_timel).css("z-index",50);
		$(".pic"+temptwo).animate({
			top: "60px",
			left: "205px", 
			width: "200px", 
			height:"100px"
		},sl_timel).css("z-index",50);
		$(".pic"+tempthree).animate({
			top: "35px",
			left: "105px", 
			width: "250px", 
			height:"150px"
		},sl_timel).css("z-index",60);

		}
		
		if (lr=="right") {
			var temptwo;
			var tempthree;
			if (tempwho==0) {
				temptwo=1;
				tempthree=2;
			}
			if (tempwho==2) {
				temptwo=0;
				tempthree=1;
			}
			if (tempwho==1) {
				temptwo=2;
				tempthree=0;
			}
			
			$(".pic"+tempthree).animate({
				top: "60px",
				left: "55px", 
				width: "200px", 
				height:"100px"
			},sl_timel).css("z-index",50);
			
			$(".pic"+tempwho).animate({
				top: "60px",
				left: "205px", 
				width: "200px", 
				height:"100px"
			},sl_timel).css("z-index",50);

			$(".pic"+temptwo).animate({
				top: "35px",
				left: "105px", 
				width: "250px", 
				height:"150px"
			},sl_timel).css("z-index",60);

			}
		
	}
	function num(who)
	{
		if (who>2) {
		who = 0;
		}
		if (who<0) {
		who = 2;
		}
		return who;
	}
})(jQuery);




function wirteHtml(data){     
    var continents = data.jobs;   
    for(var i=0;i<continents.length;i++){   
         alert(continents[i].name);   
         /*var newLine = $("#planTable").length;   
         var row = planTable.insertRow(newLine);   
         var col = row.insertCell(0);   
         col.innerHTML = continents[i].name;   
         col = row.insertCell(1);
         col.innerHTML = continents[i].age;   
         col = row.insertCell(2);   
         col.innerHTML = continents[i].email;  */ 
    }   
}   