function setLayout() {
	if (jQuery('#submit-comm-btn')) {
		jQuery('#submit-comm-btn').css({
			opacity: 0.5,
			cursor: 'default'
		});
	}
	
	jQuery('.main-menu-item').each(function(){
		jQuery(this).bind('mouseenter', function() {
			jQuery(this).attr('src', '/g/'+jQuery(this).attr('id')+'-hot.png');
		});
		jQuery(this).bind('mouseleave', function() {
			if (!jQuery(this).hasClass('current-main-menu-item')) {
				jQuery(this).attr('src', '/g/'+jQuery(this).attr('id')+'-cold.png');
			}
		});
	});
	
	jQuery('.searchform').submit(function() {
		window.location.href = this.presterm.value+'/search/'+this.hiddens.value;
		return false;
	});
	
	
	
	reLayout();
}
function reLayout() {
	winw = jQuery(document).width();
	winh = jQuery(document).height();
	
	contentwidth = 540;
	sidebarw = 250;
	rmargin = 60;
	sidebarmargin = 60;
	extraforie = 22;
	mediaportw = winw-(sidebarw+rmargin+sidebarmargin+extraforie);
	contentLmargin = winw-(contentwidth+sidebarw+rmargin+sidebarmargin+extraforie);
	
	jQuery('#container').css({
		width: mediaportw
	});
	/*
	if (jQuery('#wrapper').height()<winh) {
		jQuery('#wrapper').css({
			height: winh
		});
	}*/
	

///strat/  C O N T E N T   L E F T   M A R G I N   A D J U S T M E N T S 
	jQuery('.h1-u, h1.takespace, .breadcrumbs, .citations, .media-btns, .screenings, .creditblock, .credits, .ext-links, .content, .comments, .event-date, .event-info, .post-title, .news-num-comments, .post-date, .read-more, .forum-paging, .forum-postform, .event-archive-seasons, .forum-notice, .search-on-search').css({
		'margin-left': contentLmargin
	});
	jQuery('.h1-o').css({
		'margin-left': (contentLmargin-2)
	});
	jQuery('.film-archive-letters').css({
		'margin-left': (contentLmargin-5)
	});


///strat/  M E D I A   P O R T   A D J U S T M E N T S 
	jQuery('.mediabelt-details, .mediabelt-archive, .mediabelt-basic').each(function(){
		/// get the associated scrollbar id
		this_id = jQuery(this).attr('id');
		this_assoc_scrollbar_id = "#"+this_id.replace("-belt", "-scrollbar");
		/// the margin																																							 
		if (jQuery(this).width()<mediaportw) {
			if (jQuery(this).width()<=contentwidth) {
				lm = contentLmargin;
			} else {
				lm = mediaportw - jQuery(this).width();
			}
			/// hide the scrollbar because it's NOT needed
			jQuery(this_assoc_scrollbar_id).css({'display': 'none'});
		} else {
			lm = 0;
			/// show the scrollbar because it's needed
			jQuery(this_assoc_scrollbar_id).css({'display': 'block'});
		}
		jQuery(this).css({
			'margin-left': lm
		});
	});
///end/  M E D I A   P O R T   A D J U S T M E N T S
	
	
	
///strat/  S C R O L L B A R   A D J U S T M E N T S
	jQuery('.scrollknob').each(function(i){
		window['knob_parent_id'+i] = jQuery(this).parent().attr('id');
		window['this_assoc_belt_id'+i] = "#"+window['knob_parent_id'+i].replace("-scrollbar", "-belt");
		window['this_assoc_port_id'+i] = "#"+window['knob_parent_id'+i].replace("-scrollbar", "-port");
		window['beltw'+i] = jQuery(window['this_assoc_belt_id'+i]).width();
		window['portw'+i] = mediaportw;
		window['scrlw'+i] = mediaportw;
		window['knobw'+i] = jQuery(this).width();
		window['portscroll'+i] = jQuery(window['this_assoc_port_id'+i]).scrollLeft();
		window['knobl'+i] = ((window['scrlw'+i]-window['knobw'+i])*window['portscroll'+i])/(window['beltw'+i]-window['portw'+i]);
		
		jQuery('#'+window['knob_parent_id'+i]+' > div.scrolltrack').css('width', (window['scrlw'+i]-24));
		jQuery(this).css('left', window['knobl'+i]);

		jQuery(this).draggable({
			containment: 'parent',
			cursor: 'pointer',
			drag: function(event, ui) {
				window['knobl'+i] = parseInt(jQuery(this).css('left'));
				window['portscroll'+i] = ((window['beltw'+i]-window['portw'+i])*window['knobl'+i])/(window['scrlw'+i]-window['knobw'+i]);
				jQuery(window['this_assoc_port_id'+i]).scrollLeft(window['portscroll'+i]);
			}
		});
	});
///end/  S C R O L L B A R   A D J U S T M E N T S


}





jQuery(document).ready(function () {
	setLayout();
});
jQuery(window).load(function () {
	setLayout();
});
jQuery(window).resize(function() {
	reLayout();
});



var eng_alphabet = Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
function get_letterfilms(letter,lang) {
	jQuery.get( "/kokpit/letterfilms.php?lang="+lang, {letter:letter, currlang:lang}, function(data){ jQuery("#film-archive-port").html(data); reLayout(); jQuery(".film-archive-letters a").removeClass('current'); jQuery("#archive-"+letter+"-btn").addClass('current'); Cufon.replace('.film-archive-letters span', { fontFamily: 'dne', hover: true }); Cufon.replace('.archive-port-item-details a', { fontFamily: 'typeface6', hover: true }); /*alert("Ajax call complete."+data);*/});
	/*
	for (i=0; i<eng_alphabet.length; i++) {
		var thisletter = (letter==eng_alphabet[i]) ? 'hot' : 'cold';
		jQuery('#archive-letter-'+eng_alphabet[i]).attr('src', '/g/archive-letters/'+eng_alphabet[i]+'-'+thisletter+'.png');
	}*/
}

function get_pastevents(season,date,lang) {
	jQuery.get( "/kokpit/pastevents.php?lang="+lang, {season:season, date:date}, function(data){ jQuery("#event-archive-port").html(data); reLayout(); jQuery(".event-archive-seasons a").removeClass('current'); jQuery("#"+season+"-btn").addClass('current'); Cufon.replace('.event-archive-seasons span', { fontFamily: 'dne', hover: true }); Cufon.replace('.archive-port-item-details a', { fontFamily: 'typeface6', hover: true }); /*alert("Ajax call complete."+data);*/})
}

function load_post_media(postid,mediatype,blogindex) {
	if (!blogindex) {
		jQuery.get( "/kokpit/load_post_media.php", {postid:postid,mediatype:mediatype}, function(data){
			jQuery("#single-media-port").html(data);
			Shadowbox.setup("a.post_media_image", {gallery:"postgal"});
			reLayout();
			/*alert("Ajax call complete."+data);*/
		});
	} else {
		jQuery.get( "/kokpit/load_post_media.php", {postid:postid,mediatype:mediatype,blogindex:blogindex}, function(data){
			jQuery("#blog-media-"+postid+"-port").html(data);
			Shadowbox.setup("a."+postid+"post_media_image", {gallery:"postgal"+postid});
			reLayout();
			/*alert("Ajax call complete."+data);*/
		});
	}
}



function load_schedule(schedule_week_start,lang) {
	jQuery.get( "/kokpit/schedule.php", {schedule_week_start:schedule_week_start,currlang:lang}, function(data){ jQuery("#schedule").html(data); reLayout(); Cufon.replace('.sidebar-heading', { fontFamily: 'typeface' }); Cufon.replace('.schedule-title', { fontFamily: 'typeface6', hover: true }); /*alert("Ajax call complete."+data);*/});
}


checkform = function() {
	if (document.commentform.comment.value!='') {
		jQuery('#submit-comm-btn').css({
			opacity: 1,
			cursor: 'pointer'
		});
		jQuery('#submit-comm-btn').unbind();
		jQuery('#submit-comm-btn').bind('click', function() {
			document.commentform.submit.click();
		});
		//jQuery('submit-comm-btn').value='y';
	} else {
		jQuery('#submit-comm-btn').css({
			opacity: 0.5,
			cursor: 'default'
		});
		jQuery('#submit-comm-btn').unbind();
		//jQuery('submit-comm-btn').value='n';
	}
}
