window.onload=function () {
//$(document).ready(function() {
	setWidth();
	
	//document.body.onresize=setWidth();
	$(document).ready(function() { 
		/* This is basic - uses default settings */ 
		$("a#single_image").fancybox(); 
		
		/* Using custom settings */ 
		$("a#inline").fancybox({ 'hideOnContentClick': true }); 
		
		$("a.group").fancybox({ 'zoomSpeedIn': 300, 
		'zoomSpeedOut': 300, 
		'overlayShow': false 
		});
	});  
	
	/*$('#request').ready(function() {
		if ($('#request')!=null)
		{
			validator();
		}
	});*/
	
	$( document ).ready( function () {
	 $( '#scrolling_left' ).scrollFollow( {
	 speed: 0,
	 relativeTo: 'top',
	  killSwitch: 'exampleLink',
	 onText: 'Disable Follow',
	 offText: 'Enable Follow'
	} ); 
	} );
	
	$( document ).ready( function () {
	 $( '#scrolling_right' ).scrollFollow( {
	 speed: 0,
	 relativeTo: 'top',
	  killSwitch: 'exampleLink',
	 onText: 'Disable Follow',
	 offText: 'Enable Follow'
	} );	
	} );
	
	if ($('#validator_error_title')!=null&&$('#validator_error')!=null)
	{
		$('#validator_error_title').bind('click', function (e) {
					if ($('#validator_error').attr('class')=='validator_details')
					{
						$('#validator_error').removeClass('validator_details');
						$('#validator_error').addClass('validator_details_visible');
					}
					else
					if ($('#validator_error').attr('class')=='validator_details_visible')
					{
						$('#validator_error').removeClass('validator_details_visible');
						$('#validator_error').addClass('validator_details');
					}
				});
	}
	
	if ($('#validator_warning_title')!=null&&$('#validator_warning')!=null)
	{
		$('#validator_warning_title').bind('click', function (e) {
					if ($('#validator_warning').attr('class')=='validator_details')
					{
						$('#validator_warning').removeClass('validator_details');
						$('#validator_warning').addClass('validator_details_visible');
					}
					else
					if ($('#validator_warning').attr('class')=='validator_details_visible')
					{
						$('#validator_warning').removeClass('validator_details_visible');
						$('#validator_warning').addClass('validator_details');
					}
				});
	}
	
	if ($('#client_holder')!=null)
	{
		/*var holder=$('#client_holder');
		children=holder.$('div');*/
		children=$('.client_box_half');
		
		//alert(children);
		
		for (var i=0;i<children.length;i++)
		{
			/*if (children[i].className=='client_box_half') 
			{*/
				pcs=children[i].id.split('_');
				num=pcs[2];
				
				/*$('#grade_'+num).onclick=function () {
					showGradeBox(this);
				};*/
				
				loadStars(num);
				
				/*$('#grade_'+num).bind('click', function (e) {
					showGradeBox(this);
				});*/
				
			//}
		}
	}
	
	if ($('#grade_table')!=null)
	{
		var aspects=new Array('design','transparency','function','content');
		
		for (var x=0;x<aspects.length;x++)
		{
			var aspect_type=$('#grade_table .'+aspects[x]+'_grade');
			
			for (var i=0;i<aspect_type.length;i++)
			{
				var tmp_element=aspect_type[i];
				
				var numpcs=tmp_element.id.split('_');
				var aspect=numpcs[0];
				var num=numpcs[1];
				
				$('#'+aspect+'_'+num).bind('click', function (e) {
					var tmp_numpcs=this.id.split('_');
					var tmp_aspect=tmp_numpcs[0];
					var tmp_num=tmp_numpcs[1];
					
					addGrade(tmp_aspect,tmp_num);
					return false;
				});
			}
		}
		
	$('#grade_box_close_link').bind('click', function (e) {
		showGradeBox(this);
		return false;
	});
		
	}
	
};

function loadStars (site)
{
	$('#grade_stars_holder_'+site).load('../ajaxhandler.php?module=grade', {act:'loadstars',client:site});
	
	$('#grade_'+site).die('click');
	$('#grade_'+site).live('click', function (e) {
		showGradeBox(this);
	});
}

function addGrade(aspect,num)
{
	var site=$('#site').attr('value');
	$('#grade_submit_box').load('../ajaxhandler.php?module=grade', {act:'addgrade',aspect:aspect,grade:num,site:site},showSubmitGrade(aspect,num,site));
}

function showSubmitGrade(aspect,num,site)
{	
	var top=($('#grade_box').position().top) - 30;
	var left=(($('body').width()) /2) - (($('#grade_submit_box').width()) /2);
		$('#grade_submit_box').css('top',top+'px');
		$('#grade_submit_box').css('left',left+'px');
		$('#grade_submit_box').removeClass('grade_submit_box');
		$('#grade_submit_box').addClass('grade_submit_box_visible');
	
		$('#grade_submit_button').die('click');
		$('#grade_submit_button').live('click',function (e) {
			
			$('#grade_submit_box').load('../ajaxhandler.php?module=grade', {act:'savegrade',aspect:aspect,grade:num,site:site},closeSubmitGrade(site));
			return false; 
		});
		
		$('#grade_cancel_button').die('click');
		$('#grade_cancel_button').live('click',function (e) {
			closeSubmitGrade();
			return false; 
		});
		
		/*$('#grade_submit_button').ready(
			function (e) {
				/*$('#grade_submit_button').bind('click',function (e) {
					alert ('dfsgf');
				});*/
			/*	addSubmitGradeDetails(aspect,num,site);
			}
		);*/
		
}

function closeSubmitGrade(site)
{	
	$('#grade_submit_box').removeClass('grade_submit_box_visible');
	$('#grade_submit_box').addClass('grade_submit_box');
	$('#grade_submit_box').innerHTML='<object type="application/x-shockwave-flash" data="images/preload_orange.swf" width="40" height="40"><param name="movie" value="images/preload_orange.swf" /></object>';
	
	if (site&&site!='undefined') 
	{
		setTimeout(function()
        {
      		loadStars(site);  	
        },1000);
	}
}

function showGradeBox(element)
{
	if ($('#grade_box').attr('class')=='grade_box')
	{
		pcs=element.id.split('_');
		num=pcs[1];
		var top=($('#client_box_'+num).position().top) + 19;
		var left=(($('#client_box_'+num).position().left) + ($('#client_box_'+num).width()))-195;
		
		$('#grade_box').css('top',top+'px');
		$('#grade_box').css('left',left+'px');
		$('#grade_box').removeClass('grade_box');
		$('#grade_box').addClass('grade_box_visible');
		$('#grade_box #site').attr('value',num);
	} 
	else
	if ($('#grade_box').attr('class')=='grade_box_visible')
	{
		$('#grade_box').removeClass('grade_box_visible');
		$('#grade_box').addClass('grade_box');
	}
}

function setWidth ()
{
	/*var parentWidth=document.getElementById('container').clientWidth;
	var contentHeight=document.getElementById('container_main').clientHeight;*/
	var parentWidth=$('#container').width();
	var contentHeight=$('#container_main').height();
	var diff=parentWidth-1000;
	
	if (diff>0)
	{
		$('#left').css('width',(diff/2)+'px');
		$('#right').css('width',(diff/2)+'px');
		$('#left').css('height',contentHeight+'px');
		$('#right').css('height',contentHeight+'px');
		$('#left').css('display','block');
		$('#right').css('display','block');
	}
	else {
		$('#left').css('display','none');
		$('#right').css('display','none');
	}
	
	if ($('#content').height()>$('#sidebar_left').height()&&$('#content').height()>$('#sidebar_right').height())
	{
		$('#sidebar_left').css('height',($('#content').height())+'px');
		$('#sidebar_right').css('height',($('#content').height())+'px');
	}
	else {
		if ($('#sidebar_right').height()>$('#sidebar_left').height())
		{
			$('#sidebar_left').css('height',($('#sidebar_right').height())+'px');
		}
		else
		if ($('#sidebar_left').height()>$('#sidebar_right').height())
		{
			$('#sidebar_right').css('height',($('#sidebar_left').height())+'px');
		}
	}
	
	window.onscroll=function () {
		//alert (document.body.scrollTop);
		//alert(window.pageYOffset);
	};
}
//);

function clearInput (element)
{
	if (element.id=='name')
	{
		if (element.value=='Név') element.value='';
	}
	else
	if (element.id=='phone')
	{
		if (element.value=='Telefonszám') element.value='';
	}
	else
	if (element.id=='date')
	{
		if (element.value=='Időpont (dátum + óra:perc)') element.value='';
	}
	else
	if (element.id=='domain')
	{
		if (element.value=='weboldalának domain neve') element.value='';
	}
	else
	if (element.id=='email')
	{
		if (element.value=='E-mail cím') element.value='';
	}
	else
	if (element.id=='password')
	{
		if (element.value=='Jelszó') element.value='';
	}
}

function clearInputs ()
{
	if (document.getElementById('name')!=null)
	{
		if (document.getElementById('name').value=='Név') document.getElementById('name').value='';
	}
	if (document.getElementById('phone')!=null)
	{
		if (document.getElementById('phone').value=='Telefonszám') document.getElementById('phone').value='';
	}
	if (document.getElementById('date')!=null)
	{
		if (document.getElementById('date').value=='Időpont (dátum + óra:perc)') document.getElementById('date').value='';
	}
	if (document.getElementById('domain')!=null)
	{
		if (document.getElementById('domain').value=='weboldalának domain neve') document.getElementById('domain').value='';
	}
	if (document.getElementById('email')!=null)
	{
		if (document.getElementById('email').value=='E-mail cím') document.getElementById('email').value='';
	}
	if (document.getElementById('password')!=null)
	{
		if (document.getElementById('password').value=='Jelszó') document.getElementById('password').value='';
	}
}

function resetInput (element)
{
	if (element.id=='name')
	{
		if (element.value=='') element.value='Név';
	}
	else
	if (element.id=='phone')
	{
		if (element.value=='') element.value='Telefonszám';
	}
	else
	if (element.id=='date')
	{
		if (element.value=='') element.value='Időpont (dátum + óra:perc)';
	}
	else
	if (element.id=='domain')
	{
		if (element.value=='') element.value='weboldalának domain neve';
	}
	else
	if (element.id=='email')
	{
		if (element.value=='') element.value='E-mail cím';
	}
	else
	if (element.id=='password')
	{
		if (element.value=='') element.value='Jelszó';
	}
}
