/**
 * @author mixa
 */
var currentFamilyMenu;
var defaultFamilyJson;

var currentExtraCurrMenu;
var defaultExtraCurrJson;

var currentLeadershipMenu;
var defaultLeadershipJson;

var currentAwardsMenu;
var defaultAwardsJson;

var currentWorkExpMenu;
var defaultWorkExpJson;

var defaultHodgePodgeJson;
var defaultCourseDetailsJson;
var defaultPreferencesJson;


/**
 * populates the table with familiy member 
 * @param {Object} familyMember an object containg properties to populate the table with
 */
function showFamilyMember(familyMember,menuItem){	
	if(currentFamilyMenu){
		currentFamilyMenu.style.color='';
		currentFamilyMenu.style.backgroundColor='';
	}
	currentFamilyMenu=menuItem;
	currentFamilyMenu.style.color='white';
	currentFamilyMenu.style.backgroundColor='#CCCCCC';
	$H(familyMember).each(function(pair) {showFamilyDataRow(pair.key, pair.value);}); 
}

function showParentDetails(parentDetail){	
	$H(parentDetail).each(function(pair) {showFamilyDataRow(pair.key, pair.value);}); 
}

/**
 * a kind of standart function to show/hide the table row and populate a span with content
 * @param {Object} key of the property. Ids for Table row and span are: key+'Tr', key+'Span'
 * @param {Object} value of the property
 */
function showFamilyDataRow(key,value){
	if(value){
		$(key+'Tr').show();
		$(key+'Span').update(value);
	} else{
		$(key+'Tr').hide();
		$(key+'Span').update('');
	}
}

/* for the extra curricular - Starts*/
function showExtraCur(extraCurrAct,menuItem){	
	if(currentExtraCurrMenu){
		currentExtraCurrMenu.style.color='';
		currentExtraCurrMenu.style.backgroundColor='';
	}
	currentExtraCurrMenu=menuItem;
	currentExtraCurrMenu.style.color='white';
	currentExtraCurrMenu.style.backgroundColor='#CCCCCC';
	$H(extraCurrAct).each(function(pair) {showExtraCurrDataRow(pair.key, pair.value == 0 ? '' : pair.value );}); 
}

function showExtraCurrDataRow(key,value){
	if(value){
		$(key+'Tr').show();
		$(key+'Span').update(value);
	} else{
		$(key+'Tr').hide();
		$(key+'Span').update('');
	}
}
/* for the extra curricular - Ends*/

/* for the Leadership - Starts*/
function showLeadership(actLeadership,menuItem){	
	if(currentLeadershipMenu){
		currentLeadershipMenu.style.color='';
		currentLeadershipMenu.style.backgroundColor='';
	}
	currentLeadershipMenu=menuItem;
	currentLeadershipMenu.style.color='white';
	currentLeadershipMenu.style.backgroundColor='#CCCCCC';
	$H(actLeadership).each(function(pair) {showLeadershipDataRow(pair.key, pair.value == 0 ? '' : pair.value );}); 
}

function showLeadershipDataRow(key,value){
	if(value){
		$(key+'Tr').show();
		$(key+'Span').update(value);
	} else{
		$(key+'Tr').hide();
		$(key+'Span').update('');
	}
}
/* for the Leadership - Ends*/

/* for the Awards - Starts*/
function showAwards(actAwards,menuItem){	
	if(currentAwardsMenu){
		currentAwardsMenu.style.color='';
		currentAwardsMenu.style.backgroundColor='';
	}
	currentAwardsMenu=menuItem;
	currentAwardsMenu.style.color='white';
	currentAwardsMenu.style.backgroundColor='#CCCCCC';
	$H(actAwards).each(function(pair) {showAwardsDataRow(pair.key, pair.value == 0 ? '' : pair.value );}); 
}

function showAwardsDataRow(key,value){
	if(value){
		$(key+'Tr').show();
		$(key+'Span').update(value);
	} else{
		$(key+'Tr').hide();
		$(key+'Span').update('');
	}
}
/* for the Awards - Ends*/

/* for the WorkExp - Starts*/
function showWorkExp(actWorkExp,menuItem){	
	if(currentWorkExpMenu){
		currentWorkExpMenu.style.color='';
		currentWorkExpMenu.style.backgroundColor='';
	}
	currentWorkExpMenu=menuItem;
	currentWorkExpMenu.style.color='white';
	currentWorkExpMenu.style.backgroundColor='#CCCCCC';
	$H(actWorkExp).each(function(pair) {showWorkExpDataRow(pair.key, pair.value == 0 ? '' : pair.value );}); 
}

function showWorkExpDataRow(key,value){
	if(value){
		$(key+'Tr').show();
		$(key+'Span').update(value);
	} else{
		$(key+'Tr').hide();
		$(key+'Span').update('');
	}
}
/* for the WorkExp - Ends*/

/* for the HodgePodge - Starts*/
function showHodgePodge(hodgePodge){	
	$H(hodgePodge).each(function(pair) {showDataRow(pair.key, pair.value == 0 ? '' : pair.value );});
}

/* for the HodgePodge - Ends*/


/* for the Future - Starts*/
function showFutureDetails(futureDet){	
	$H(futureDet).each(function(pair) {showDataRow(pair.key, pair.value == 0 ? '' : pair.value );});
}

/* for the Future - Ends*/

/* for the Courses - Starts*/
function showCoursesDetails(courseDet){	
	$H(courseDet).each(function(pair) {showDataRow(pair.key, pair.value == 0 ? '' : pair.value );});
}

/* for the Courses - Ends*/

/* for the Preferences - Starts*/
function showPreferences(preferenceDet){	
	$H(preferenceDet).each(function(pair) {showDataRow(pair.key, pair.value == 0 ? '' : pair.value );});
}

/* for the Preferences - Ends*/


function showDataRow(key,value){
	if(value){
		$(key+'Tr').show();
		$(key+'Span').update(value);
	} else{
		$(key+'Tr').hide();
		$(key+'Span').update('');
	}
}

// For showing the Files and Images in the z-Folio panel

function showFolioFile(fileInfo, modalControl,fileType, controls){
    $extend(modalControl).style.display = "none";
	$extend(controls.ShowTitle).update(fileInfo.Title);
	$extend(controls.ShowShortDescription).update(fileInfo.ShortDescription);
	//$(controls.ShowTags).update(fileInfo.Tags);
	//$(controls.ShowActivity).update(fileInfo.Activity);
	//we hide all placeholders for all file types
	$extend(controls.ShowFileImage, controls.ShowFileWriting, controls.ShowFileVideo).invoke('hide'); 
	//Text=2,	Graphic=3,	Audio=4, Video=5	
	var filePath="../ZinchFiles/"+fileInfo.Fullpath.replace(/\\/g,"/"); //TODO fix this to be from application config
	if(fileType==2){ //Writing
		$extend(controls.ShowFileWriting).show();
		$extend(controls.ShowFileWriting).getElementsBySelector('iframe').first().src=filePath;
	} else if(fileType==3){ // Graphic
		$extend(controls.ShowFileImageContainer).show();
		$extend(controls.ShowFileImage).show();
		$extend(controls.ShowFileImage).src=filePath;
	} else if(fileType==4){ // Audio		
		var so = new SWFObject("../FlashFiles/playerSingle.swf", "mymovie", "192", "67", "7", "#FFFFFF");
		so.addVariable("autoPlay", "yes");
   		so.addVariable("soundPath", filePath);
		so.addVariable("playerSkin","1");
  		so.addVariable("overColor","#000033");
   		so.write($extend(controls.ShowFileAudio).id);
		$extend(controls.ShowFileAudio).show();
	} else if(fileType==5){ // Video
		if(fileInfo.ShowFromFliqz=="true"){ //for old clips only
			var so = new SWFObject("http://www.fliqz.com/p.swf?file="
								+fileInfo.VideoId+"&autoplay=1&progressive=1", "mymovie", "450", "360", "8", "#FFFFFF");	
			so.addVariable("wmode", "transparent");		
			so.write($extend(controls.ShowFileVideo).id);
		} else {			
			var playerObject = '<embed src="'+filePath+'" width="500" height="400" />';
			$extend(controls.ShowFileVideo).update(playerObject);			
		}
		$extend(controls.ShowFileVideo).show();
	}	
	
	var ie=document.all && !window.opera;
	var dom=document.getElementById;
	iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body;
	var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset;
	var docwidth=(ie)? iebody.clientWidth : window.innerWidth;
	docheight=(ie)? iebody.clientHeight: window.innerHeight;
	var objwidth=$extend(modalControl).offsetWidth;
	objheight=$extend(modalControl).offsetHeight;
	//$(modalControl).style.left="380px";
	
	var scroll_left=(ie)? iebody.scrollLeft : window.pageXOffset;
	$extend(modalControl).style.left= parent.$extend(modalControl).style.width; //document.documentElement.clientWidth/2 - 400+ "px"; // $(modalControl).parentNode.clientWidth + "px"; //scroll_left + docwidth/2-200 + "px"; // docwidth/2 + "px"; //$(modalControl).parentNode.clientWidth/2 + "px";
	$extend(modalControl).style.top=scroll_top+15-objheight+"px";
	$extend(modalControl).style.display="block";
}

/**
 * Is used to do some closing stuff like stop playing etc
 * @param {Object} modalControl
 * @param {Object} fileType
 * @param {Object} controls
 */
function hideFolioFile(modalControl, controls){
    $extend(controls.ShowFileImage).src="../images/loading.gif";
	$extend(controls.ShowFileImageContainer).hide();
    $extend(controls.ShowFileAudio).update(''); 
    $extend(controls.ShowFileVideo).update('');
    $extend(controls.ShowFileImage, controls.ShowFileWriting, controls.ShowFileVideo).invoke('hide');
    $extend(modalControl).style.display="none";
}

