// JavaScript Document

<!-- Code for checkboxes -->
$(document).ready(function() { 
					   
	$(".checklist .checkbox-select").click( 
		function(event) { 
			event.preventDefault(); 
			$(this).parent().addClass("selected"); 
			$(this).parent().find(":checkbox").attr("checked","checked"); 
			
			} ); 
	$(".checklist .checkbox-deselect").click( 
		function(event) { 
			event.preventDefault(); 
			$(this).parent().removeClass("selected"); 
			$(this).parent().find(":checkbox").removeAttr("checked"); 
						
			} 
	);
}); 
<!-- end code for checkboxes -->

<!-- Function For Show/Hide boxes -->
	function EnableDisableDIV(checkboxID,divID, arrPos){ 
	
		
		if (document.getElementById(checkboxID).checked==false) { 
			$('#button-' + divID).css("background-position", -(arrPos*48) + "px 0px");
			$('#panel-' + divID).show(); 
			document.getElementById(checkboxID).checked=true; 
		} else { 
			$('#button-' + divID).css("background-position",-(arrPos*48) + "px -48px");
			$('#panel-' + divID).hide(); 
			document.getElementById(checkboxID).checked=false; 
		} 
		write_chkcookie();
	} 

<!-- Function for initial Show/Hide boxes -->	
	function EnableDisableDIV_Initial(checkboxID,divID,arrPos){ 

		if (document.getElementById(checkboxID).checked==true) { 
			EnableDIV_Initial(divID,arrPos);	
		} else { 
			DisableDIV_Initial(divID,arrPos);		
		}
	}
	
	function EnableDIV_Initial(divID,arrPos){
			$('#button-' + divID).css("background-position",-(arrPos*48) + "px 0px");	
			$('#panel-' + divID).show(); 
			$('#button-' + divID).addClass("selected"); 
			$('#button-' + divID).find(":checkbox").attr("checked","checked"); 	
	}

	function DisableDIV_Initial(divID,arrPos){
			$('#button-' + divID).css("background-position",-(arrPos*48) + "px -48px");				
			$('#panel-' + divID).hide();
			$('#button-' + divID).removeClass("selected"); 
			$('#button-' + divID).find(":checkbox").removeAttr("checked"); 			
	}

<!-- Function for checking cookies -->	
	function write_chkcookie(){ 		
		/*var chkboxArray = ['articles','latestnews','services','multimedia','news','weather','asxetolinks','pedia','books','afierwmata']; */
		/*var chkboxArray = ['articles']; */
		var chkcookie_str = ''; 
		for ( var i=0, len=chkboxArray.length; i<len; ++i ){ 
			chkcookie_str = chkcookie_str + chkboxArray[i]+':'; 
			
			var chkbox = document.getElementById('checkButton' +chkboxArray[i]); 
			if (chkbox.checked==true) { 
				chkcookie_str =chkcookie_str + 'true,'; 
			} else { 
				chkcookie_str =chkcookie_str + 'false,'; 
			} 
		} 
		chkcookie_str = chkcookie_str.substring(0, chkcookie_str.length-1); 
		$.cookie('visibility_cookie', chkcookie_str,{ expires: 10000 }); 
	} 
  

<!-- Function to generate the control panel for the panels -->	
	function generatePanelCP(){	
	 for(var i=0;i<chkboxArray.length;i++){ 
	 
		   var outLi = '';
		   outLi = '<li style="background-image:url(\'/Portals/0/images/web-design/homepageicons.jpg\');background-position:' + -(i*48) + 'px 0px" id="button-' + panelIdArray[i] + '">';
		   outLi+= '  <input name="checkButton' + chkboxArray[i] + '" value="checkButton' + chkboxArray[i] + '" id="checkButton' + chkboxArray[i] + '" type="checkbox" >';
		   outLi+= '  <a class="checkbox-select" href="#" onclick="EnableDisableDIV(\'checkButton' + chkboxArray[i] + '\',\'' + panelIdArray[i] + '\',' + i +')"></a> ';
		   outLi+= '  <a class="checkbox-deselect" href="#" onclick="EnableDisableDIV(\'checkButton' + chkboxArray[i] + '\',\'' + panelIdArray[i] + '\', ' + i + ')"></a> ';
		   outLi+= '</li>';	  
		   document.write(outLi);	
; 		   
		   

		}
	
		//ToolTips for the icons
		$(document).ready(function() { 	
			for(var i=0;i<chkboxArray.length;i++){ 
		  // alert('#panel-' + panelIdArray[i] + ' = ' + jQuery('#panel-' + panelIdArray[i] + ' h2').html() );
		   jQuery('#panel-' + panelIdArray[i] + ' h2 .Head').prepend('<strong><img border="0" src="/Portals/0/images/web-design/homepage/icons/' + chkboxArray[i] + '.png" alt=""></strong>');
		   
				$('#button-'+ panelIdArray[i]).qtip({
					content: descrArray[i],
					position: {
						corner: {
							target: 'topMiddle',
							tooltip: 'bottomMiddle'
						}
					}
				});
			}
		});
	}		
	
	  

<!-- Cookies code -->
	$(document).ready(function() {

		var visibility_string = $.cookie('visibility_cookie'); 
		if (visibility_string!=null){ 
			var chkbox_value_pair_string = visibility_string.split(","); 
			for(i=0;i<chkbox_value_pair_string.length;i++){ 
				var chkbox_value_string=chkbox_value_pair_string[i]; 
				var chkbox_value = chkbox_value_string.split(":"); 
				var chkboxid = chkbox_value[0]; 
				var value = chkbox_value[1]; 
				var chkbox = document.getElementById('checkButton' +chkboxid); 
				if(chkbox != null){
					if (value=='true') { chkbox.checked=true } else { chkbox.checked=false } 
					var divid=''; 
					switch (chkboxid) { 
						case 'articles': divid='971'; break; 
						case 'latestnews': divid='415'; break; 
						case 'services': divid='401'; break; 
						case 'multimedia': divid='967'; break; 
						case 'news': divid='968'; break; 
						case 'weather': divid='402'; break; 
						case 'asxetolinks': divid='1420'; break; 
						case 'pedia': divid='1437'; break; 
						case 'books': divid='1398'; break; 
						case 'afierwmata': divid='1632'; break; 
						case 'grifoi': divid='969'; break; 
						case 'games': divid='966'; break; 
						case 'cinema': divid='1111'; break; 
					} 
			
					EnableDisableDIV_Initial('checkButton' + chkboxid, divid, i);
				}
			}
		}else //if no settings are save set every icon to enabled
		{
			for(var i=0;i<chkboxArray.length;i++){ 
				var divID = panelIdArray[i];				
				EnableDIV_Initial(panelIdArray[i],i)			
			}
		}
	
	})

function clearPanelCookies(){

	$.cookie('position_cookie', null,	{ path: '/', expires: -5 });
	$.cookie('visibility_cookie', null,	{ path: '/', expires: -5 });	
	$.cookie('panel_positions', null,	{ path: '/', expires: -5 });	
}
