// JavaScript Document

function change_css( $p_type, $p_style )
{

	$('.css_' + $p_type).attr('href', APP_ASSETS + 'css/' + $p_type + '_' + $p_style + '.css');
    
    $.cookie('css_' + $p_type, $p_style, { path: '/', expires: 30 });

}

$().ready(function()
{
	$('a.lightbox').lightBox({txtImage: '',txtOf: '/'});

	if( typeof( $('ul.articles').height() ) != 'undefined' && typeof( $('ul.links').height() ) != 'undefined'  )
	{
		if( $('ul.articles').height() < $('ul.links').height() )
		{
			$('ul.articles').css('height', $('ul.links').height()); 
		}
		else
		{
			$('ul.links').css('height', $('ul.articles').height()); 
		}
	}
	$('html').bind( 'click', hide_color_examples );

	files_height();

	if ($('#heading_main').height() > 30)
	{
		$('#overlay_main').css('height','73px');
	}


});


/* IE6 Hover fix */
sfHover = function() {
	var sfEls = document.getElementById("colors").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function show_color_examples ( t ) 
{
	hide_color_examples();
	$(t).parent().children('ul').css('left','auto');
	
}

function hide_color_examples ()
{
	$('#site_colors > ul > li > ul').css('left','-999em' );
}

function set_mtop ( t )
{
	$mtop = ( 182 - $(t).height() ) / 2;
	$(t).css("margin-top", $mtop);
}

function files_height ()
{
	file = $('.files_list li a');
	for ( var i=0, j=1; j<file.length; i++, j++ )
	{
		
		if ( ( $(file[j]).height() < $(file[i]).height() ) && ( j % 2 == 1) )
		{
			var margin = Math.round( ($(file[i]).height() - $(file[j]).height()) / 2) + 15;
			$(file[j]).css("padding-top", margin + 'px');
			$(file[j]).css("padding-bottom", margin + 'px');
		}
		else if ( ( $(file[j]).height() > $(file[i]).height() ) && ( j % 2 == 1) )
		{
			var margin = Math.round( ($(file[j]).height() - $(file[i]).height()) / 2) + 15;
			$(file[i]).css("padding-top", margin + 'px');
			$(file[i]).css("padding-bottom", margin + 'px');
		}
	}
}
