// Scripts to surve goods(objects) section
// v .01

// initializing varibles

 

$(document).ready(function () {
app={
	lnagId:	$('#appSettingsContainer').attr('langId') || 1,
	loadingImg : '<img src="/wrap/i/loader.gif" />' 
};
inface.init();
//	All AJAX calls erorrReporter	
});



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inface = {};

inface.init = function(){
inface.goodies();	
//inface.cycleScrooler();	// add cycler if neceesery
inface.imageCycleScrooler();
inface.windowing();			// add TOContents float window
$('#theArticleDetail ul').tabs({'fxSlide': true,    'fxSpeed': 'fast' });
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inface.goodies= function(){
inface.imageCyclerPrep();
$('#quote P.theQuote').wrapInner('<div class="preQ"></div>');
};	


inface.windowing= function(){
$('body').append('<div class="jqmWindow" id="toc">'+app.loadingImg+'</div>');
$('#toc').jqm(
  	{ajax: '/wrap/contents.html?langId='+app.lnagId, 
  		trigger: '#contents a'
  		, overlay: 50, 
//    		overlayClass: 'whiteOverlay',
    		toTop: true
  	});	
};

inface.cycleScrooler= function(){
	if($('BODY.dark').size() > 0){
var ah1 = $('BODY.dark #theArticle h1')  ;
var ah2 = $('BODY.dark #theArticle h2') ;
var ahp = $('BODY.dark #theArticle P') ;
} 
else if ($('BODY.light').size() > 0){
var ah1 = $('BODY.light #theArticle h1') ;
var ah2 = $('BODY.light #theArticle h2');
var ahp = $('BODY.light #theArticle p');
	}
	var tx = $('#theArticle p').eq(0).text();
//tx.length
if($(ahp).size() >2 || $(ahp).text().length > 400){
	var cont= '';
	$.each( ahp, function(i, n){ cont = cont+'<p>'+$(ahp[i]).html()+'</p>';	});
	var cy = '<div id="aCycler">'+cont+'</div>';
	$('#theArticle').html('').append(ah2,ah1,cy);
	
	$('BODY.dark #aCycler, BODY.light #aCycler').after('<a href="#" id="cyclePrev">«</a><span id="cycleScrooler"></span><a href="#"id="cycleNext">»</a>')
	.cycle({ 
	    fx:    'scrollHorz', 
	    pause:  1 ,
	    timeout: 6000,
	    delay: 1000,
	    pager: '#cycleScrooler',
	    next:   '#cycleNext', 
    		prev:   '#cyclePrev' 
	    
	}); 

};

$('#theArticle').wrapInner('<div class="articleWrapper"></div>')		
};

inface.imageCycleScrooler= function(){
	if($('P.aCycler IMG').size() > 0){
	$('p.aCycler')
	.after('<div id="cycleNaviLigh"><a href="#" id="cyclePrev">«</a><span id="cycleScrooler"></span><a href="#"id="cycleNext">»</a></div>')
	.cycle({ 
	    fx:    'scrollHorz', 
	    pause:  1 ,
	    timeout: 6000,
	    delay: 1000
	    ,
	    pager: '#cycleScrooler',
	    next:   '#cycleNext', 
    		prev:   '#cyclePrev'     
	}); 	
 }; 
 

	var cImg = $('IMG.aCycler');
	$.each(cImg, function(i,o){
	// inject DOM is new parent is Not exist
//console.log('>', $(o).parent('div').html());

}); 
};
 
inface.imageCyclerPrep = function(){
 
if($('IMG.aCycler').size() > 1){
	var cImg = $('IMG.aCycler');
	$.each(cImg, function(i,o){
		// inject DOM is new parent is Not exist
		if($('#iCycler').size() == 0){
    			//$(o).parent('div').prepend('<div id="iCycler"></div>');
    			$(o).before('<div id="iCycler"></div>');
    			 }
    			 var newParnt = $('#iCycler');
		$(o).removeClass('aCycler').clone(true).appendTo(newParnt).end().remove();
		});
		

}
inface.imageCyclerRun();
};	

inface.imageCyclerRun = function(){		
$('#iCycler')
	.after('<div id="cycleNaviLigh"><a href="#" id="cyclePrev">«</a><span id="cycleScrooler"></span><a href="#"id="cycleNext">»</a></div>')
	.cycle({ 
	    fx:    'scrollHorz', 
	    pause:  1 ,
	    timeout: 6000,
	    delay: 1000
	    ,
	    pager: '#cycleScrooler',
	    next:   '#cycleNext', 
    		prev:   '#cyclePrev'     
	}); 
		
}; 
//else if ($('BODY.light').size() > 0){
//var ah1 = $('BODY.light #theArticle h1') ;
//var ah2 = $('BODY.light #theArticle h2');
//var ahp = $('BODY.light #theArticle p');
//	}
//	var tx = $('#theArticle p').eq(0).text();
////tx.length
//if($(ahp).size() >2 || $(ahp).text().length > 400){
//	var cont= '';
//	$.each( ahp, function(i, n){ cont = cont+'<p>'+$(ahp[i]).html()+'</p>';	});
//	var cy = '<div id="aCycler">'+cont+'</div>';
//	$('#theArticle').html('').append(ah2,ah1,cy);
	


//};
//
//$('#theArticle').wrapInner('<div class="articleWrapper"></div>')		
 
