$(document).ready(function(){
	initTabs();
	initGall();
	initExpand();
	
	initViewAll();
	initChangeStatus();
	
	initPoll();
	addComment();
	initVisualImages();
	//fixIE6Flicker();
});

/*--- clear inputs function ---*/
function clearInputs(){		
	var _input = document.getElementsByTagName('input');
	for(var i = 0; i < _input.length; i++){
		if(_input[i].type == 'text' || _input[i].type == 'password'){
			_input[i]._val = _input[i].value;
			_input[i].onfocus = function(){
				if(this.value == this._val) this.value = '';
			}
			_input[i].onblur = function(){
				if(this.value == '') this.value = this._val;
			}
		}
	}
}
/*-----------------------------*/

/*--- gallery ---*/
function initExpand(){
	//$('.box-hold').hide();
	$('.but-collapse-this-panel').click(function()
	{		
		$(this).toggleClass('active');
		$(this.parentNode).next('.box-hold').slideToggle(300);
	});
}
function initExpandAjax(cat_id)
{
	var btn = $('#'+cat_id);
	//alert(btn.parent().html());
	//$('#'+cat_id).toggleClass('active');
	$(btn).parent().next('.box-hold').show();
}
function initViewAll(){
	
	var call = $('.but-view-all');
	call.click(function()
	{	
		var name = $(this).attr("name");
		attr_array = name.split("#");
		cat_id = attr_array[0];
		cat_nm = attr_array[1];
		
		var div_name = "#box-hold-"+cat_id;
		var head_div_name = "#heading-"+cat_id;
		var rnd_no = Math.random();
		query = "";
		//alert("view all");
		try{
			/*
			$("div_name").ajaxStart(function(){
			$(this).show();
			});
			
			$("div_name").ajaxStop(function(){
			$(this).hide();
			});
			*/
			$(div_name).ajaxStart(function(){
				showAjaxModalPanel();
			});
			$(div_name).ajaxStop(function(){
				hideAjaxModalPanel();
			});
			var funcRefToPositionBox = function positionBox() {
				var boxWidth = 100; // retrieve box width here
				var boxHeight = 60; // retrieve box height here
				$('#LoadingPanel').css({marginLeft: '-' + parseInt(boxWidth / 2) +
				'px', width: boxWidth + 'px'});
				if ( !(jQuery.browser.msie && typeof XMLHttpRequest == 'function')) { // take away IE6
					$('#LoadingPanel').css({marginTop: '-' + parseInt(boxHeight / 2) +
					'px'});
				}	
				//alert('inside me');
			}
			$(window).scroll( funcRefToPositionBox );
			$(window).resize( funcRefToPositionBox );			
			
			//alert(div_name);
			$.post(Drupal.settings['base_path'] + '?q=' +"dashboard/category/view_all/"+cat_id+"/"+rnd_no,query, function(data){  
				//alert("text:" + data);
				data_array = data.split("#custom_separator#");
				data = data_array[0];
				flag_rows = data_array[1];
				
				$(div_name).html(data); 
				//alert("flag_rows="+flag_rows);
				if(flag_rows==1)
				{
					heading_button_data = '<h3>'+ cat_nm +'</h3><a href="javascript:;" id="but-collapse-'+cat_id+'" class="but-collapse-this-panel active">Collapse This Panel</a><a href="javascript:;" name="'+cat_id+'#'+cat_nm+'" class="but-view-all">View All</a>';
					$(head_div_name).html(heading_button_data); 
					
					/* Rebinding the click event to the loaded html start */
					$('.but-view-all').each(function(i) {
            		$(this).unbind('click');
					});
					$('.but-collapse-this-panel').each(function(i) {
						$(this).unbind('click');
					});
					initViewAll();
					initExpand();
					initExpandAjax('but-collapse-'+cat_id);
					/* Rebinding the click event to the loaded html start */
				}
				
				/* Rebinding the click event to the loaded html start */
				$('.but-complete').each(function(i) {
            		$(this).unbind('click');
        		});
				$('.but-postpon').each(function(i) {
            		$(this).unbind('click');
        		});
				initChangeStatus();
				/* Rebinding the click event to the loaded html ends */
				
				
					
				//$(div_name).load(data);  
				//initChangeStatus(); //buttons in the current section is not working
			}); 
		}catch(e){
			alert(e);
		}
	});
	
}
function showAjaxModalPanel(){
	//IE hack for modal
	jQuery.each(jQuery.browser, function(i) {
	  if($.browser.msie){
		 var boxMargin = (document.documentElement && document.documentElement.scrollTop || document.body.scrollTop); 
		 //alert(boxMargin);
		 var marginTop = (0 - parseInt(document.getElementById('LoadingPanel').offsetHeight / 2) + boxMargin + 'px');
		 //alert(parseInt(document.getElementById('LoadingPanel').offsetHeight / 2));
		 $("#LoadingPanel").css("position","absolute");
		 $("#LoadingPanel").css("margin-top",marginTop);
	  }
	});

	document.getElementById('AjaxModalPanel').style.display = "block";
	document.getElementById('AjaxModalPanel').style.height = document.documentElement.scrollHeight + 'px';
	document.getElementById('LoadingPanel').style.display = "block";
}

function hideAjaxModalPanel(){
	document.getElementById('AjaxModalPanel').style.display = "none";
	document.getElementById('LoadingPanel').style.display = "none";
}
function initChangeStatus(){
	
	var call = $('.but-complete');
	call.click(function()
	{	
		var name = $(this).attr("name");
		//alert(name);
		attr_array = name.split("#");
		cat_id = attr_array[0];
		init_id = attr_array[1];
		cat_nm = attr_array[2];
		/*var div_name = "#box-hold-"+cat_id;
		var div_name2 = "#box-hold2-"+cat_id; //for completed tab
		var top_div_name2 = "#box-2-"+cat_id; //for top completed tab
		
		var head_div_name = "#heading-"+cat_id;  //in recomended tab
		var head_div_name2 = "#heading2-"+cat_id; //in completeed tab*/
		query = "";
		try{
			
			$(this).ajaxStart(function(){
				showAjaxModalPanel();
			});
			$(this).ajaxStop(function(){
				hideAjaxModalPanel();
			});
			var funcRefToPositionBox = function positionBox() {
				var boxWidth = 100; // retrieve box width here
				var boxHeight = 60; // retrieve box height here
				$('#LoadingPanel').css({marginLeft: '-' + parseInt(boxWidth / 2) +
				'px', width: boxWidth + 'px'});
				if ( !(jQuery.browser.msie && typeof XMLHttpRequest == 'function')) { // take away IE6
					$('#LoadingPanel').css({marginTop: '-' + parseInt(boxHeight / 2) +
					'px'});
				}	
				//alert('inside me');
			}
			$(window).scroll( funcRefToPositionBox );
			$(window).resize( funcRefToPositionBox );
			
			//alert(div_name);
			$.post(Drupal.settings['base_path'] + '?q=' +"update_dashboard/"+cat_id+"/"+init_id+"/complete",query, function(data){  
				//alert("text:" + data);
				/*data_array = data.split("#custom_separator#");
				data = data_array[0];
				flag_rows = data_array[1];
				compl_data = data_array[2];
				top_score = data_array[3];*/
				
				//$("#progress-box").html(top_score); //for score updation and graph updation
				//$(div_name).html(data);        //for recomened tab
				//$(div_name2).html(compl_data); //for completed tab 
				
				
				
				
				///////////////////////////////////////////
				
				//updateDashboard();
				data_array = data.split("*@#@*");
				$('#content0').html(data_array[0]);
				$('#content1').html(data_array[1]);
				
				initTabs();
				initViewAll();
				initChangeStatus();
				initExpand();
				hideAjaxModalPanel();
				//hideAjaxModalPanel();
				//alert('hello');
				//This is for populating the completed tab and opening up the collapse button
				/*heading_button_data2 = '<h3>'+ cat_nm +'</h3>';
				$(head_div_name2).html(heading_button_data2);
				$(head_div_name2).addClass('heading');
				$(top_div_name2).addClass('box');*/
				//hideAjaxModalPanel();
				//If no rows are there then the heading is redrawn with changed collapse button
			/*	if(flag_rows==0)
				{					
					heading_button_data = '<h3>'+ cat_nm +'</h3><a href="javascript:;" class="but-collapse-this-panel">Collapse This Panel</a><a href="javascript:;" name="'+cat_id+'#'+cat_nm+'" class="but-view-all">View All</a>';
					$(head_div_name).html(heading_button_data); 
					
					// Rebinding the click event to the loaded html start //
					$('.but-view-all').each(function(i) {
            		$(this).unbind('click');
					});
					$('.but-collapse-this-panel').each(function(i) {
						$(this).unbind('click');
					});
					initViewAll();
					initExpand();
					// Rebinding the click event to the loaded html start //
				}*/
				
				
				/* Rebinding the click event to the loaded html start */
				/*$('.but-complete').each(function(i) {
            		$(this).unbind('click');
        		});
				$('.but-postpon').each(function(i) {
            		$(this).unbind('click');
        		});*/
				//initChangeStatus();
				/* Rebinding the click event to the loaded html ends */
				
			}); 
		}catch(e){
			alert(e);
		}
	});
	
	
	var call2 = $('.but-postpon');
	call2.click(function()
	{	
		var name = $(this).attr("name");
		attr_array = name.split("#");
		cat_id = attr_array[0];
		init_id = attr_array[1];
		cat_nm = attr_array[2];
		
		/*var div_name = "#box-hold-"+cat_id;
		var head_div_name = "#heading-"+cat_id;*/
		query = "";
		try{
			
			/*$(div_name).ajaxStart(function(){
				showAjaxModalPanel();
			});
			$(div_name).ajaxStop(function(){
				hideAjaxModalPanel();
			});*/
			$(this).ajaxStart(function(){
				showAjaxModalPanel();
			});
			$(this).ajaxStop(function(){
				hideAjaxModalPanel();
			});
			var funcRefToPositionBox = function positionBox() {
				var boxWidth = 100; // retrieve box width here
				var boxHeight = 60; // retrieve box height here
				$('#LoadingPanel').css({marginLeft: '-' + parseInt(boxWidth / 2) +
				'px', width: boxWidth + 'px'});
				if ( !(jQuery.browser.msie && typeof XMLHttpRequest == 'function')) { // take away IE6
					$('#LoadingPanel').css({marginTop: '-' + parseInt(boxHeight / 2) +
					'px'});
				}	
				//alert('inside me');
			}
			$(window).scroll( funcRefToPositionBox );
			$(window).resize( funcRefToPositionBox );
			
			
			//alert(div_name);
			$.post(Drupal.settings['base_path'] + '?q=' +"update_dashboard/"+cat_id+"/"+init_id+"/postpon",query, function(data){ 
				data_array = data.split("*@#@*");
				$('#content0').html(data_array[0]);
				$('#content1').html(data_array[1]);
				
				initTabs();
				initViewAll();
				initChangeStatus();
				initExpand();
				hideAjaxModalPanel();
				//alert("text:" + data);
				/*data_array = data.split("#custom_separator#");
				data = data_array[0];
				flag_rows = data_array[1];
				
				$(div_name).html(data);  
				
				//If no rows are there then the heading is redrawn with changed collapse button
				if(flag_rows==0)
				{					
					heading_button_data = '<h3>'+ cat_nm +'</h3><a href="javascript:;" class="but-collapse-this-panel">Collapse This Panel</a><a href="javascript:;" name="'+cat_id+'#'+cat_nm+'" class="but-view-all">View All</a>';
					$(head_div_name).html(heading_button_data); 
					
					// Rebinding the click event to the loaded html start //
					$('.but-view-all').each(function(i) {
            		$(this).unbind('click');
					});
					$('.but-collapse-this-panel').each(function(i) {
						$(this).unbind('click');
					});
					initViewAll();
					initExpand();
					
				}*/
				
				/* Rebinding the click event to the loaded html start */
				/*$('.but-complete').each(function(i) {
            		$(this).unbind('click');
        		});
				$('.but-postpon').each(function(i) {
            		$(this).unbind('click');
        		});
				initChangeStatus();*/
				/* Rebinding the click event to the loaded html ends */
				
			});
		}catch(e){
			alert(e);
		}
		
	});
	
}

function ready(cat_id,init_id,cat_nm){
	
	var div_name = "#box-hold-"+cat_id;
	var head_div_name = "#heading-"+cat_id;
	query = "";
	try{
			$(div_name).ajaxStart(function(){
				showAjaxModalPanel();
			});
			$(div_name).ajaxStop(function(){
				hideAjaxModalPanel();
			});
			var funcRefToPositionBox = function positionBox() {
				var boxWidth = 100; // retrieve box width here
				var boxHeight = 60; // retrieve box height here
				$('#LoadingPanel').css({marginLeft: '-' + parseInt(boxWidth / 2) +
				'px', width: boxWidth + 'px'});
				if ( !(jQuery.browser.msie && typeof XMLHttpRequest == 'function')) { // take away IE6
					$('#LoadingPanel').css({marginTop: '-' + parseInt(boxHeight / 2) +
					'px'});
				}	
				//alert('inside me');
			}
			$(window).scroll( funcRefToPositionBox );
			$(window).resize( funcRefToPositionBox );
			
			$.post(Drupal.settings['base_path'] + '?q=' +"update_dashboard/"+cat_id+"/"+init_id+"/ready",query, function(data){  
			data_array = data.split("*@#@*");
				$('#content0').html(data_array[0]);
				$('#content1').html(data_array[1]);
				
				initTabs();
				initViewAll();
				initChangeStatus();
				initExpand();
				hideAjaxModalPanel();
			// Rebinding the click event to the loaded html ends //
			
		});
	}catch(e){
		alert(e);
	}
}

function undo(cat_id,init_id,cat_nm){
	
	
	var div_name = "#box-hold-"+cat_id;
	var div_name2 = "#box-hold2-"+cat_id; //for completed tab
	var top_div_name2 = "#box-2-"+cat_id; //for top completed tab
	//var head_div_name = "#heading-"+cat_id;
	var head_div_name2 = "#heading2-"+cat_id; //in completeed tab
	query = "";
	
	try{
			$(div_name).ajaxStart(function(){
				showAjaxModalPanel();
			});
			$(div_name).ajaxStop(function(){
				hideAjaxModalPanel();
			});
			
			var funcRefToPositionBox = function positionBox() {
				var boxWidth = 100; // retrieve box width here
				var boxHeight = 60; // retrieve box height here
				$('#LoadingPanel').css({marginLeft: '-' + parseInt(boxWidth / 2) +
				'px', width: boxWidth + 'px'});
				if ( !(jQuery.browser.msie && typeof XMLHttpRequest == 'function')) { // take away IE6
					$('#LoadingPanel').css({marginTop: '-' + parseInt(boxHeight / 2) +
					'px'});
				}	
				//alert('inside me');
			}
			$(window).scroll( funcRefToPositionBox );
			$(window).resize( funcRefToPositionBox );
			
			$.post(Drupal.settings['base_path'] + '?q=' +"update_dashboard/"+cat_id+"/"+init_id+"/undo",query, function(data){  
			data_array = data.split("*@#@*");
				$('#content0').html(data_array[0]);
				$('#content1').html(data_array[1]);
				
				initTabs();
				initViewAll();
				initChangeStatus();
				initExpand();
				hideAjaxModalPanel();
				//$('a.tab#a-tab-completed').trigger('click');
			// Rebinding the click event to the loaded html ends //
			
		});
	}catch(e){
		alert(e);
	}
	
}

/*
function initGall(){
	try{
	$('.gallery').each(function(){
		var gall_hold = $(this);
		var list_hold = gall_hold.find('.photos');
		var _list = list_hold.children();
		var btn_next = gall_hold.find('.toolbar .next');
		var btn_prev = gall_hold.find('.toolbar .prev');
		var _a = 0;
		var _step = gall_hold.width();
		if(_a == 0) btn_prev.parent().addClass('disabled');
		if(_a == _list.length - 1) btn_next.parent().addClass('disabled');
		
		btn_next.click(function(){
			if(!$(this).parent().is('.disabled')) nextEl(_a + 1);
			return false;
		});
		btn_prev.click(function(){
			if(!$(this).parent().is('.disabled')) nextEl(_a - 1);
			return false;
		});
		
		function nextEl(_ind){
			if(_ind < 1) btn_prev.parent().addClass('disabled');
			else btn_prev.parent().removeClass('disabled');
			if(_ind > _list.length - 2) btn_next.parent().addClass('disabled');
			else btn_next.parent().removeClass('disabled');
			list_hold.animate({marginLeft: -_step*_ind}, { queue:false, duration:300});
			_a = _ind;
		}
	});
	}catch(e1){
			alert(e1);
	}
}
*/
/*--- gallery function ---*/
function initGall(){
	var _hold = document.getElementById('gallery');
	if(_hold){
		var _a = -1;
		var _c;
		var _t;
		var btn_prev = document.getElementById('btn-gall-prev');
		var btn_next = document.getElementById('btn-gall-next');
		var _list = _hold.getElementsByTagName('li');
		for(var i = 0; i < _list.length; i++){
			if(_list[i].className.indexOf('acitve') != -1) _a = i;
			_list[i].style.opacity = 0;
			_list[i].style.MozOpacity = 0;
			_list[i].style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
			_list[i]._p = 0;
			_list[i]._f = 0;
		}
		if(_a == -1) _a = 0;
		if(_list[_a].className.indexOf('active') == -1) _list[_a].className += ' active';
		_list[_a].style.opacity = 1;
		_list[_a].style.MozOpacity = 1;
		_list[_a].style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
		_list[_a]._p = 100;
		
		_hold.style.visibility = "visible";
		
		if(btn_prev && btn_next){
			if(_a == 0) btn_prev.parentNode.className += ' disabled';
			if(_a == _list.length -1) btn_next.parentNode.className += ' disabled';
			if(_list.length > 1){
				btn_prev.onclick = function(){
					if(this.parentNode.className.indexOf('disabled') == -1){
						changeEl(_a - 1);
					}
					return false;
				}
				btn_next.onclick = function(){
					if(this.parentNode.className.indexOf('disabled') == -1){
						changeEl(_a + 1);
					}
					return false;
				}
			}
			else{
				btn_prev.onclick = function(){
					return false;
				}
				btn_next.onclick = function(){
					return false;
				}
			}
		}
		function changeEl(_ind){
			if(_t) clearTimeout(_t);
			if(_ind == 0) btn_prev.parentNode.className += ' disabled';
			else btn_prev.parentNode.className = btn_prev.parentNode.className.replace('disabled','');
			
			if(_ind == _list.length -1) btn_next.parentNode.className += ' disabled';
			else btn_next.parentNode.className = btn_next.parentNode.className.replace('disabled','');
			
			_list[_a].className = _list[_ind].className.replace('active','');
			if(_list[_ind].className.indexOf('active') == -1) _list[_ind].className += ' active';
			_c = 0;
			_a = _ind;
			changeOpacity();
		}
		function changeOpacity(){
			_c++;
			for(var i = 0; i < _list.length; i++){
				if(i == _a){
					if(_list[i]._p < 100){
						_list[i]._p += 4;
						_list[i].style.opacity = _list[i]._p*0.01;
						_list[i].style.MozOpacity = _list[i]._p*0.01;
						_list[i].style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+_list[i]._p+')';
					}
				}
				else if(_list[i]._p > 0){
					_list[i]._p -= 4;
					_list[i].style.opacity = _list[i]._p*0.01;
					_list[i].style.MozOpacity = _list[i]._p*0.01;
					_list[i].style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+_list[i]._p+')';
				}
			}
			if(_c <= 25){
				_t = setTimeout(function(){
					changeOpacity();
				}, 10);
			}
		}
	}
}
/*--- tabs ---*/
function initTabs() {
	try{
	$('.tabset').each(function(_ind, _el) {
		var btn_h = $(_el);
		var _btn = $(_el).find('a.tab');
		var _a = 0;
		_btn.each(function(_ind, _el) {
			var _box = $('#'+_el.href.substr(_el.href.indexOf("#") + 1));
			if($(_el).is('.active')) {
				_box.show();
				_a = _ind;
			}
			else {
				_box.hide();
			}
			_el.onclick = function() {
				if(!$(this).is('.active')){
					$('#'+ _btn.get(_a).href.substr(_btn.get(_a).href.indexOf("#") + 1)).hide();
					_btn.eq(_a).removeClass('active');
					$('#'+ this.href.substr(this.href.indexOf("#") + 1)).show();
					$(this).addClass('active');
					_a = _ind;
				}
				return false;
			}
		});
	});
	}catch(e){
			alert(e);
	}
}

function initPage()
{
	var rates = document.getElementsByTagName("ul");
	for (i = 0; i < rates.length; i ++)
	{
		if (rates[i].className.indexOf("star-rating") != -1)
		{
			rates[i]._lis = rates[i].getElementsByTagName("li");
			
			rates[i].onmouseover = function() {
				//alert('debug');
				for (k = 0; k < this._lis.length; k++)
				{
					if (this._lis[k].className.indexOf("active") != -1)
					{
						//alert('debug');
						this._active = this._lis[k];
						this._activeindex = k;
						this._lis[k].className = this._lis[k].className.replace("active", "");
					}
				}
			}
			rates[i].onmouseout = function() {
				//This is a flag to check if it is clicked
				ifclicked = false;
				if (this._active && this._active.className.indexOf("active") == -1)
				{
					for (k = 0; k < this._lis.length; k++)
					{
						if (this._lis[k].className.indexOf("active") != -1  && (k != this._activeindex))
						{
							//alert('debug');
							ifclicked = true;
							break;
						}
					}
					if(!ifclicked)
					this._active.className += " active";
				}
			}
			
		}
	}
}
//function to handle the click event of voting system
function initPoll(){
	$('.star-rating li').each(function(){
		this.onclick = function(){
			this.className += " active";
			//query = this.html();
			var current_star = $(this);
			var initiative_id = current_star.parent().attr("id"); 
			var rating = current_star.children("a").attr("href").substr(1);
			query ="";
			$(current_star).ajaxStart(function(){
				showAjaxModalPanel();
			});
			$(current_star).ajaxStop(function(){
				hideAjaxModalPanel();
			});
			//alert(Drupal.settings['base_path'] + '?q=' +"dashboard/detail/rating/"+initiative_id+"/"+rating+"/");
			$.post(Drupal.settings['base_path'] + '?q=' +"dashboard/detail/rating/"+initiative_id+"/"+rating+"/",query, function(data){  
            	//alert('rating complete');  
			});
		}
	});
}
function  addComment(){
		$('.btn-add-comment').click(function(){
			var button_comment = $(this);	
			var initiative_id = $(document).find("#init_id").val();
			var initiative_comment = $(document).find("#comment").val();
			//query = '{ comment: "'+comment+'",init_id:"'+initiative_id+'" }';
			//alert(query);
			if(initiative_comment.length<=0){
				alert('Please enter a comment');
			}
			if(initiative_id.length>0 && initiative_comment.length>0){
				//clearing the comment textfield
				$(document).find("#comment").val("");
				$(button_comment).ajaxStart(function(){
					showAjaxModalPanel();
				});
				$(button_comment).ajaxStop(function(){
					hideAjaxModalPanel();
				});
				$.post(Drupal.settings['base_path'] + '?q=' +"dashboard/detail/add_comment/",{ comment: initiative_comment,init_id:initiative_id }, function(data){  
					hideAjaxModalPanel();																																		 					
					//alert('comment posted');  
					//document.getElementById('posted').style.display = "block";
					$("#posted").fadeIn("slow");
					setTimeout ( 'hideCommentStatus()', 5000 );

				});
			}
		});
}
function hideCommentStatus(){
	$("#posted").fadeOut("slow");
}

function initVisualImages(){
	var _hold = document.getElementById('visuals');
	if(_hold){
		var _a = -1;
		var _c;
		var _t;
		//var btn_prev = document.getElementById('btn-gall-prev');
		//var btn_next = document.getElementById('btn-gall-next');
		var nav_0 = document.getElementById('nav_0');
		var nav_1 = document.getElementById('nav_1');
		var nav_2 = document.getElementById('nav_2');
		var nav_3 = document.getElementById('nav_3');
		var nav_4 = document.getElementById('nav_4');
		
		var _list = _hold.getElementsByTagName('img');
		
		for(var i = 0; i < _list.length; i++){
			//if(_list[i].className.indexOf('acitve') != -1) _a = i;
			_list[i].style.opacity = 0;
			_list[i].style.MozOpacity = 0;
			_list[i].style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
			_list[i]._p = 0;
			_list[i]._f = 0;
		}
		if(_a == -1) _a = 0;
		if(_list[_a].className.indexOf('active') == -1) _list[_a].className += ' active';
		_list[_a].style.opacity = 1;
		_list[_a].style.MozOpacity = 1;
		_list[_a].style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
		_list[_a]._p = 100;
		
		_hold.style.visibility = "visible";
		
		
		
		if(nav_0){
			nav_0.onclick = function(){
				inactivateAllTabs();
				nav_0.className = 'active';
				changeEl(1);
			}
		}
		if(nav_1){
			nav_1.onclick = function(){
				inactivateAllTabs();
				nav_1.className = 'active';
				changeEl(2);
			}
		}
		if(nav_2){
			nav_2.onclick = function(){
				inactivateAllTabs();
				nav_2.className = 'active';
				changeEl(3);
			}
		}
		if(nav_3){
			nav_3.onclick = function(){
				inactivateAllTabs();
				nav_3.className = 'active';
				changeEl(4);
			}
		}
		if(nav_4){
			nav_4.onclick = function(){
				inactivateAllTabs();
				nav_4.className = 'active';
				changeEl(5);
			}
		}
		
		function inactivateAllTabs(){
			nav_4.className = '';
			nav_3.className = '';
			nav_2.className = '';
			nav_1.className = '';
			nav_0.className = '';
		}
		/*if(btn_prev && btn_next){
			if(_a == 0) btn_prev.parentNode.className += ' disabled';
			if(_a == _list.length -1) btn_next.parentNode.className += ' disabled';
			if(_list.length > 1){
				btn_prev.onclick = function(){
					if(this.parentNode.className.indexOf('disabled') == -1){
						changeEl(_a - 1);
					}
					return false;
				}
				btn_next.onclick = function(){
					if(this.parentNode.className.indexOf('disabled') == -1){
						changeEl(_a + 1);
					}
					return false;
				}
			}
			else{
				btn_prev.onclick = function(){
					return false;
				}
				btn_next.onclick = function(){
					return false;
				}
			}
		}*/
		
		function changeEl(_ind){
			if(_t) clearTimeout(_t);
			//if(_ind == 0) btn_prev.parentNode.className += ' disabled';
			//else btn_prev.parentNode.className = btn_prev.parentNode.className.replace('disabled','');
			
			//if(_ind == _list.length -1) btn_next.parentNode.className += ' disabled';
			//else btn_next.parentNode.className = btn_next.parentNode.className.replace('disabled','');
			
			_list[_a].className = _list[_ind].className.replace('active','');
			if(_list[_ind].className.indexOf('active') == -1) _list[_ind].className += ' active';
			_c = 0;
			_a = _ind;
			changeOpacity();
		}
		function changeOpacity(){
			_c++;
			for(var i = 0; i < _list.length; i++){
				if(i == _a){
					if(_list[i]._p < 100){
						_list[i]._p += 4;
						_list[i].style.opacity = _list[i]._p*0.01;
						_list[i].style.MozOpacity = _list[i]._p*0.01;
						_list[i].style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+_list[i]._p+')';
					}
				}
				else if(_list[i]._p > 0){
					_list[i]._p -= 4;
					_list[i].style.opacity = _list[i]._p*0.01;
					_list[i].style.MozOpacity = _list[i]._p*0.01;
					_list[i].style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+_list[i]._p+')';
				}
			}
			if(_c <= 25){
				_t = setTimeout(function(){
					changeOpacity();
				}, 1);
			}
		}
	}
}
function drFormSubmit(){
	try{
		var drForm = document.forms['download-report-form'];
		if((drForm.name.value == 'Name - required')){
				alert(drForm.name.value);
				return false;
		}
		else if((drForm.email.value == 'Email - required')){
				alert(drForm.email.value);
				return false;
		}
		else if(validate('download-report-form','email')==false){
				alert('Invalid Email Address');
				return false;
		}
		else if((drForm.name.value != 'Name - required')&&(drForm.email.value != 'Email - required')){
				//alert('name:'+drForm.name.value+' email:'+drForm.email.value);
				return true;
		}
		/*else{
				alert('no');
		}*/
		
	}catch(e){ 
		alert(e);
	}
}

function validate(form_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {
      //alert('Invalid Email Address');
      return false;
   }
}
/*function updateDashboard(){
		$.post(Drupal.settings['base_path'] + '?q=' +"update_dashboard",query, function(data){
					//alert(data);
					data_array = data.split("*@#@*");
					$('#content0').html(data_array[0]);
					$('#content1').html(data_array[1]);
					//$('#content1').html('123');
					//alert(data_array[0]);
					//alert(data_array[1]);
		});
}*/
//webspiders - This function fixes the image flicker in ie6 for background images
function fixIE6Flicker(){
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}
}

if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPage);
