// Scripts to surve goods(objects) section
// v .01s


$(document).ready(function () {
 	readInitialSettings();
	start(); 
});

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function readInitialSettings(){
var serverCfg = $('#appSettigsContainer');
//var defTags = $('#appSettigsContainerTags').val(); 
var appCfg = {
	cfgPath	: serverCfg.attr('cfgPath'),
	appName	: "portfolioAdmin",
	xmlResponder 	: serverCfg.attr('xmlProcessor'),
	requstedItemId : serverCfg.attr('requstedItemId') || 0,
	myNameIs 	:  serverCfg.attr('myNameIs') || 'unknown'
	};

app = {
	cfg :	{},	// configuration will be injected here
	state:	{projectId:0},	//  current state here
	data:	{},	// all projects data will be stored here
	tags: [],
	inProcess:{}   //will inject currently displayed keys
		
	}; 
//
$.extend(app.cfg, appCfg );
//$.extend(app.tags, eval(defTags) );//init tags data
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// onLoad Events
function start(){
//$.taconite.debug = true;
//var cycleScreen =  $('.anImage');
//$.fn.cycleTo.defaults = { 
//    height:  'auto',   // container height 
//    fade:     1,       // true for fade, false for slide 
//    speed:    1100,     // any valid fx speed value 
//    timeout:  3600,    // ms duration for each slide 
//    random:   0,       // true for random, false for sequence 
//    fit:      0,       // force slides to fit container 
//    pause:    1        // true to enable "pause on hover" 
//    , 
//    screen: cycleScreen
//};
//
//$('#slideContent').cycleTo(); 
	p8Projects.init();
 

}; //end START




p8Projects = {
init 	:function(){

$('#tagBody').hide();
$('#tagger').hide();
 p8Projects.appendImageActions();

//add custom IDs
//$('#navigator li a').each(function (){
//		thisHref = $(this).attr('href');
//		var isPortfolio = (thisHref.substring(0,11) == '/portfolio/');
//		var isJob = (thisHref.substring(0,5) == '/job/');
//		if (isPortfolio){	$(this).attr('id','portfolio2go')	}
//		if (isJob){	$(this).attr('id','job2go')	}
//	});

//surve portfolio button
//$('#portfolio2go').hover(function (){
//		thisHref = $(this).attr('href');
//		$(this).addClass('open');
//		 $('#tagger').SlideInUp(500);
//		return false;	 
//	}, function (){
////		$(this).removeClass('open');
////		$('#tagger').SlideOutUp('slow');
//		return false;	
//	}
//
//);
//	$('a.tagSwitcher').hover(function() {
//			var keyId = $(this).attr('objid') || 0; //keyId = tagId
// 			$('a.tagSwitcher').removeClass('current');
// 			$(this).addClass('current');
// 			
//			$('.tagglink').parent('li').hide(); 
//			$('.tagg'+keyId).parent('li').SlideInUp(650);
//			$('#tagBody').SlideInUp(500); 
//			return false;
//		},function() {}
//	);
// p8Projects.appendProjectLoader();
// 	p8Projects.initInterface();
	},
appendProjectLoader: function(){
		$('a.tagglink').click(function() {
		var thisObjId = $(this).attr('objid');
		if (thisObjId > 0){
			p8Projects.loadProject(thisObjId);
			return false;
			
			}
		else {
			return true;
			};
		
	});
	},
appendImageActions: function(){
		$('a.iLink').click(function() {
		var thisObjId = $(this).attr('imgLink') || null;
		if (thisObjId){ 
			$('a.iLink').removeClass('clicked');
			$(this).addClass('clicked');
			p8Projects.displayBigImage(thisObjId);
			return false;
			 
			}
		else {
			return true;
		 
			};
		
	});
	},
displayBigImage: function(iname){
	$('.anImage').fadeOut('slow', function(){
		$(this).html('<img src="'+iname+'" />');
		
		});
	$('.anImage').fadeIn('fast');
 	},
loadProject: function(thisObjId){	
	$('#appScreen').html('<div class="bigLoader">Загрузка...</div>');
 
	$('#appScreen').load(
			app.cfg.xmlResponder,
	 		{ action: "gProject" , projectId:thisObjId},
	 		function(){ 
//	 			$('.anImageSequence').cycle( { random: 0, fade:1 } );
	 			p8Projects.appendImageActions();
	 			 
	 	}).fadeIn('slow');
	},
loadAllObjects :function(){
		$.getJSON(
			app.cfg.xmlResponder,
	 		{ jsonAction: "getProjectsJSON" },
	 		function(json){ 
	 			$.extend(app.data, json);
	 			rStatus('ok', timestamp+' <b>Данные загружены.</b>');
	 			aList.init();
	 			p8Projects.goUpdateScreen();
				
	 	});
		},	
initInterface:function(){ 
		// pre appScreeen
 					//$('#appScreenUpdate').show();
		//p8Projects.preUpdateScreen();	//prepare BrowseUpdateScreen
		//p8Projects.preNewScreen();		//prepare New Screen
		
		}
}; 
  


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//<div id="slideContent">
//<a class="iLink" imglink="/portfolio/anh/corporateImage/emba-imageguide-0.png" title="emba-imageguide-0.png " href="?project=13&image=57"> 1</a>
//<a class="iLink" imglink="/portfolio/anh/corporateImage/emba-imageguide-2.png" title="emba-imageguide-2.png " href="?project=13&image=59"> 2 </a>
//<a class="iLink" imglink="/portfolio/anh/corporateImage/emba-imageguide-1.png" title="emba-imageguide-1.png " href="?project=13&image=58"> 3 </a>
//<a class="iLink" imglink="/portfolio/anh/corporateImage/emba-imageguide-3.png" title="emba-imageguide-3.png " href="?project=13&image=55"> 4 </a>
//<a class="iLink" imglink="/portfolio/anh/corporateImage/emba-image1.jpg" title="emba-image1.jpg " href="?project=13&image=56"> 5 </a>
//</div>

function initSlideShow(){
var slideScreen= $('.anImage');	
$('#slideContent a').click(function() {
		var thisObjId = $(this).attr('imgLink') || null;
		if (thisObjId){
			displaySlide(thisObjId);
			return false;
			
			}
		else {
			return true;
			};
		
	});
if (slideScreen.css('position') == 'static') slideScreen.css('position', 'relative');
slideScreen.html('<div class="bigLoader">Загрузка...</div>');
$('.bigLoader').css('position','absolute');
};



function  displaySlide(srcHref){
         	var htm = '<img src ="'+srcHref+'" title ="'+srcHref+'">';
	$('.anImage img').css('z-index', 1);
	$(htm).css('z-index', 99).css('position','absolute');
	 $screen.append(htm).css('z-index', els.length-i).css('position','absolute').hide();
        	$('.anImage').prepend(htm)	;
        		
};
