var loadFunc = null;
var loadTimer = null;
var MY_CONTROLLER;
var MY_METHOD;
var MY_QAID = null;

function doLoad() {
	if (loadTimer !== null) {
		clearTimeout(loadTimer);
		loadTimer = null;
	}
	
	if (loadFunc !== null) {
		loadTimer = setTimeout(loadFunc + '()', 1);
	}
}

function clickTag(tag) {
	if ($("#fltrTag").length) {
		$("#fltrTag").val(tag);
		$("#clearFltrTag").show();
		doLoad();
	}
}

function postLoad() {
	if ($(".viewTable").length) {
		$(".viewTable").corners();
	}
	if ($(".editlink").length) {
		$(".editlink").click(function(e) {
			var myId = $(this).attr('rel');
			$("#viewBody" + myId).toggle();
			$("#editBody" + myId).toggle();
			fixContentSize();
			e.preventDefault();
		});
		
		$(".editForm").ajaxForm(function(r) {
			var myId = $(this).attr('rel');
//			alert(r);
			if (r == 1) {
				doLoad();
			} else {
				$("#editFeedback" + myId).html(r);
				fixContentSize();
				setTimeout("$('#editFeedback" + myId + "').html('');	fixContentSize();", 5000);
			}
		});
		
		$("input[type=button],input[type=submit],input[type=reset]").button();
	}
	
	if ($(".dellink").length) {
		$(".dellink").click(function(e) {
			var delStr = $(this).attr('title');
			if (delStr == '') {
				delStr = 'Delete This';
			}
			if (confirm('Are You Sure You Want To ' + delStr + '?')) {
				$.post($(this).attr('href'), {id: $(this).attr('rel')}, function(r) {
					if (r == 1) {
						doLoad();
					} else {
						alert('ERROR: ' + r);
					}
				});
			}
			e.preventDefault();
		});
	}
	
	if ($("#contentContainer .dpicker").length) {
		$("#contentContainer .dpicker").datepicker();	
	}
	
	if ($(".editCancelBtn").length) {
		$(".editCancelBtn").click(function() {
			var myId = $(this).attr('rel');
			$("#viewBody" + myId).toggle();
			$("#editBody" + myId).toggle();
			$("#editForm" + myId).resetForm();
			
			$(".newTypeSelect").each(function() {
				var rel = $(this).attr('rel');
				var val = $(this).val();
		
				if (val !== 'NEW') {
					$(".newTypeContainer[rel=" + rel + "]").hide();
				} else {
					$(".newTypeContainer[rel=" + rel + "]").show();
				}
			});
	
			$(".newSizeSelect").each(function() {
				var rel = $(this).attr('rel');
				var val = $(this).val();
		
				if (val !== 'NEW') {
					$(".newSizeContainer[rel=" + rel + "]").hide();
				} else {
					$(".newSizeContainer[rel=" + rel + "]").show();
				}
			});
			
			fixContentSize();
		});
	}

	if ($(".viewTable .thumbUploader").length) {
		$(".viewTable .thumbUploader").each(function() {
			var rel = $(this).attr('rel');
			$("#" + rel + "_urlContainer").hide();
			$(this).find(".urlLink").unbind('click').click(function(e) {
				$("#" + rel + "_useFile").val('0');
				$("#" + rel + "_upldContainer").hide();
				$("#" + rel + "_urlContainer").show();
				e.preventDefault();
			});
			
			$(this).find(".upldLink").unbind('click').click(function(e) {
				$("#" + rel + "_useFile").val('1');
				$("#" + rel + "_upldContainer").show();
				$("#" + rel + "_urlContainer").hide();
				e.preventDefault();
			});
		});
	}

	
	if ($("#paging_links").length) {
		$("#paging_links a").click(function(e) {
			var offset = $(this).attr('href').replace('/', '');
			$("#CURR_PAGE").val(offset);
			doLoad();
			
			e.preventDefault();
		});
	}
	
	$(".newTypeSelect").each(function() {
		var rel = $(this).attr('rel');
		var val = $(this).val();
		
		if (val !== 'NEW') {
			$(".newTypeContainer[rel=" + rel + "]").hide();
		} else {
			$(".newTypeContainer[rel=" + rel + "]").show();
		}
		
		$(this).unbind('change').change(function() {
			if ($(this).val() == 'NEW') {
				$(".newTypeContainer[rel=" + rel + "]").show();
			} else {
				$(".newTypeContainer[rel=" + rel + "]").hide();
			}
		});
	});
	
	$(".newSizeSelect").each(function() {
		var rel = $(this).attr('rel');
		var val = $(this).val();
		
		if (val !== 'NEW') {
			$(".newSizeContainer[rel=" + rel + "]").hide();
		} else {
			$(".newSizeContainer[rel=" + rel + "]").show();
		}
		
		$(this).unbind('change').change(function() {
			if ($(this).val() == 'NEW') {
				$(".newSizeContainer[rel=" + rel + "]").show();
			} else {
				$(".newSizeContainer[rel=" + rel + "]").hide();
			}
		});
	});
	
	loadTags('.tagsContainer');
	loadStats();
	fixContentSize();
}

function loadStats() {
	if ($("#statsBlock").length) {
		var statsUrl = '/' + MY_CONTROLLER + '/loadstats/';
			
		if ($("#STATS_URL").length) {
			statsUrl = $("#STATS_URL").val();
		}

		$("#statsBlock .body").load(statsUrl, function() {
			loadTagClouds(".tagCloud");
		});
	}
}

function loadTagClouds(selector) {
	$(selector).each(function() {
		var rt = $(this).attr('rel');
		
		$(this).load('/tags/loadcloud/' + rt, function() {
			$(selector + " .clickTag").unbind('click').click(function(e) {
				var myTag = $(this).attr('href');
				if (myTag !== '') {
					clickTag(myTag);
				}
				e.preventDefault();
			});
			
			setTimeout('fixContentSize();', 100);
		});
	});
}

function loadTags_orig(selector) {
	if ($(selector)) {
		$(selector).each(function() {
			var myId = $(this).attr('id').split('_');
			var refType = myId[1];
			var theId = myId[2];
			var refKey = refType + '_' + theId;
			
			$.post('/tags/loadtags', {rt: refType, id: theId}, function(r) {
				$("#" + myId[0] + '_' + myId[1] + '_' + myId[2]).html(r);
				$(".clickTag").unbind('click').click(function(e) {
					var myTag = $(this).attr('href');
					if (myTag !== '') {
						clickTag(myTag);
					}
					e.preventDefault();
				});
				$(".actag").autocomplete({source: '/actags.php', delay: 100});
				fixContentSize();
				
				var myTag = $("#tag_" + refKey).val();
			
				if (myTag == '') {
					$("#tagLink_" + refKey).hide();
				} else {
					$("#tagLink_" + refKey).show();
				}
			
				$("#tag_" + refKey).keyup(function() {
					myTag = $("#tag_" + refKey).val();
				
					if (myTag == '') {
						$("#tagLink_" + refKey).hide();
					} else {
						$("#tagLink_" + refKey).show();
					}
				});
			
				$("#tagLink_" + refKey).click(function(e) {
					var myId = $(this).attr('id').split('_');
					var refType = myId[1];
					var theId = myId[2];
					var refKey = refType + '_' + theId;

					tag(refType, theId, $("#tag_" + refKey).val());
					e.preventDefault();
				});
			
				$(".deltaglink").click(function(e) {
					var myId = $(this).attr('rel');
					delTag(myId, refType, theId);
					e.preventDefault();
				});
				
				fixContentSize();
			});
		});
	}
}

function loadTags(selector) {
	if ($(selector)) {
		var containers = '';
		var ii = 0;
		$(selector).each(function() {
			var myId = $(this).attr('id').split('_');
			var refType = myId[1];
			var theId = myId[2];
			var refKey = refType + '_' + theId;
			
			if (ii > 0) {
				containers += ',';
			}
			
			containers += $(this).attr('id');
			ii++;
		});
		
		$.post('/tags/loadtags2', {ctrs: containers}, function(r) {
			var tmp = containers.split(',');
			
			for (ii = 0; ii < tmp.length; ii++) {
				var c = tmp[ii];
				var myId = tmp[ii].split('_');
				var refType = myId[1];
				var theId = myId[2];
				var refKey = refType + '_' + theId;
//				alert($("#" + tmp[ii], r).html());
				$("#" + c).html($("#" + c, r).html());
				var myTag = $("#tag_" + refKey).val();
			
				if (myTag == '') {
					$("#tagLink_" + refKey).hide();
				} else {
					$("#tagLink_" + refKey).show();
				}
				
				$("#tag_" + refKey).keyup(function() {
					myTag = $(this).val();
				
					if (myTag == '') {
						$("#tagLink_" + $(this).attr('rel')).hide();
					} else {
						$("#tagLink_" + $(this).attr('rel')).show();
					}
				});
				
				$("#tagLink_" + refKey).click(function(e) {
					var myId = $(this).attr('id').split('_');
					var refType = myId[1];
					var theId = myId[2];
					var refKey = refType + '_' + theId;

					tag(refType, theId, $("#tag_" + refKey).val());
					e.preventDefault();
				});
				
				// modify this to only work on the ones we just added
				$("#" + c + " .deltaglink").unbind('click').click(function(e) {
					var myId = $(this).attr('rel');
					delTag(myId, refType, theId);
					e.preventDefault();
				});
				// put tags in place, assign js to the stuff
			}

			$(".actag").autocomplete({source: '/actags.php', delay: 100});
			$(".clickTag").unbind('click').click(function(e) {
				var myTag = $(this).attr('href');
				if (myTag !== '') {
					clickTag(myTag);
				}
				e.preventDefault();
			});
			
			setTimeout('fixContentSize();', 1000);
		});

	}
}


function loadPreTags() {
	if ($("#preTagsContainer").length) {
		$.post('/tags/loadpretags', {QAID: MY_QAID}, function(r) {
			$("#preTagsContainer").html(r);
			$(".clickTag").unbind('click').click(function(e) {
				var myTag = $(this).attr('href');
				if (myTag !== '') {
					clickTag(myTag);
				}
				e.preventDefault();
			});
			$(".actag").autocomplete({source: '/actags.php', delay: 100});
			fixContentSize();
			
			var myPreTag = $("#pretag").val();
			
			if (myPreTag == '') {
				$("#preTagLink").hide();
			} else {
				$("#preTagLink").show();
			}
			
			$("#pretag").keyup(function() {
				myPreTag = $("#pretag").val();
				
				if (myPreTag == '') {
					$("#preTagLink").hide();
				} else {
					$("#preTagLink").show();
				}
			});
			
			$("#preTagLink").click(function(e) {
				preTag();
				e.preventDefault();
			});
			
			$(".delptlink").click(function(e) {
				var myIdx = $(this).attr('rel');
				delPreTag(myIdx);
				e.preventDefault();
			});
		});
	}
}

function delPreTag(myIdx) {
	if ($("#preTagsContainer").length) {
		$.post('/tags/deletepretag', {QAID: MY_QAID, idx: myIdx}, function(r) {
			if (r == 1) {
				loadPreTags();
			} else {
				alert('ERROR: ' + r);
			}
		});
	}
}

function delTag(myId, rt, rid) {
	$.post('/tags/deletetag', {id: myId}, function(r) {
		if (r == 1) {
			loadTagClouds(".tagCloud");
			loadTags("#tags_" + rt + "_" + rid);
		} else {
			alert('ERROR: ' + r);
		}
	});
}

function clearPreTags() {
	if ($("#preTagsContainer").length) {
		$.post('/tags/clearpretags', {QAID: MY_QAID}, function(r) {
			if (r == 1) {
				loadPreTags();
			} else {
				alert('ERROR: ' + r);
			}
		});
	}
}

function preTag() {
	var myTag = $("#pretag").val();
	
	$.post('/tags/pretag', {QAID: MY_QAID, tag: myTag}, function(r) {
		if (r == 1) {
			$("#pretag").val('');
			$("#preTagLink").hide();
			loadPreTags();
		} else {
			alert('ERROR: ' + r);
		}
	});
}

function tag(myRefType, myId, myTag) {
	$.post('/tags/tag', {rt: myRefType, id: myId, tag: myTag}, function(r) {
		if (r == 1) {
			$("#tag_" + myRefType + "_" + myId).val('');
			$("#tagLink_" + myRefType + "_" + myId).hide();
			loadTagClouds(".tagCloud");
			loadTags('#tags_' + myRefType + "_" + myId);
		} else {
			alert('ERROR: ' + r);
		}
	});
}

function loadPreLcs() {
	if ($("#preLcsContainer").length) {
		$.post('/linkcodes/loadprelcs', {QAID: MY_QAID}, function(r) {
			$("#preLcsContainer").html(r);
			
			$(".delPreLcLink").unbind('click').click(function(e) {
				var myIdx = $(this).attr('href');
				$.post('/linkcodes/deleteprelc', {QAID: MY_QAID, idx: myIdx}, function(r) {
					if (r == 1) {
						loadPreLcs();
					} else {
						alert('ERROR: ' + r);
					}
				});
				
				e.preventDefault();
			});
			
			$("#preLcType").unbind('change').change(function() {
				if ($(this).val() == 'NEW') {
					$("#preLcNewType").show();
				} else {
					$("#preLcNewType").hide();
				}
			});
			
			if ($("#preLcType").val() != 'NEW') {
				$("#preLcNewType").hide();
			}
			
			if ($("#preLcUrl").val() == '') {
				$("#addPreLcLink").hide();
			}
			
			$("#preLcUrl").unbind('keyup').keyup(function() {
				if ($(this).val() == '') {
					$("#addPreLcLink").hide();
				} else {
					$("#addPreLcLink").show();
				}
			});
			
			$("#addPreLcLink").unbind('click').click(function(e) {
				var tid = $("#preLcType").val();
				var nt = $("#preLcNewType").val();
				var lcUrl = $("#preLcUrl").val();
					
				$.post('/linkcodes/prelc', {QAID: MY_QAID, type: tid, newType: nt, url: lcUrl}, function(r) {
					if (r == 1) {
						loadPreLcs();
					} else {
						$("#preLcFeedback").html(r).show();
						setTimeout('$("#preLcFeedback").html("").hide()', 5000);
					}
				});
				
				e.preventDefault();
			});
		});
	}
}

function clearPreLcs() {
	if ($("#preLcsContainer").length) {
		$.post('/linkcodes/clearprelcs', {QAID: MY_QAID}, function(r) {
			if (r == 1) {
				loadPreLcs();
			} else {
				alert('ERROR: ' + r);
			}
		});
	}
}

function loadPreUrls() {
	if ($("#preUrlsContainer").length) {
		$.post('/galurls/loadpreurls', {QAID: MY_QAID}, function(r) {
			$("#preUrlsContainer").html(r);
			
			$(".delPreUrlLink").unbind('click').click(function(e) {
				var myIdx = $(this).attr('href');
				$.post('/galurls/deletepreurl', {QAID: MY_QAID, idx: myIdx}, function(r) {
					if (r == 1) {
						loadPreUrls();
					} else {
						alert('ERROR: ' + r);
					}
				});
				
				e.preventDefault();
			});
			
			$("#preUrlType").unbind('change').change(function() {
				if ($(this).val() == 'NEW') {
					$("#preUrlNewType").show();
				} else {
					$("#preUrlNewType").hide();
				}
			});
			
			if ($("#preUrlType").val() != 'NEW') {
				$("#preUrlNewType").hide();
			}
			
			if ($("#preUrlUrl").val() == '') {
				$("#addPreUrlLink").hide();
			}
			
			$("#preUrlUrl").unbind('keyup').keyup(function() {
				if ($(this).val() == '') {
					$("#addPreUrlLink").hide();
				} else {
					$("#addPreUrlLink").show();
				}
			});
			
			$("#addPreUrlLink").unbind('click').click(function(e) {
				var tid = $("#preUrlType").val();
				var nt = $("#preUrlNewType").val();
				var urlUrl = $("#preUrlUrl").val();
					
				$.post('/galurls/preurl', {QAID: MY_QAID, type: tid, newType: nt, url: urlUrl}, function(r) {
					if (r == 1) {
						loadPreUrls();
					} else {
						$("#preUrlFeedback").html(r).show();
						setTimeout('$("#preUrlFeedback").html("").hide()', 5000);
					}
				});
				
				e.preventDefault();
			});
		});
	}
}

function clearPreUrls() {
	if ($("#preUrlsContainer").length) {
		$.post('/galurls/clearpreurls', {QAID: MY_QAID}, function(r) {
			if (r == 1) {
				loadPreUrls();
			} else {
				alert('ERROR: ' + r);
			}
		});
	}
}


function fixContentSize() {
	// width
	var ww = $(window).width();
	var pcw = $("#pagecontent").width();
	var pbw = $("#pagebody").width();
	var acw = $("#actualContent").width();
	var mw = (ww-(200+275));
	var mw2 = (ww-200);

	if ($("#midcontent").length) {
		if ($("#midcontent").width() < mw) {
			$("#midcontent").width(mw);
		} else {
			if (acw <= mw) {
				$("#midcontent").width(mw);
			}
		}
	}
	
	if ($("#fullcontent").length) {
		if ($("#fullcontent").width() < mw2) {
			$("#fullcontent").width(mw2);
		} else {
			if (acw <= mw2) {
				$("#fullcontent").width(mw2);
			}
		}
	}

	if (acw >= mw) {
		$("#actualContent").width(mw);
		acw = mw;
	}

	if ($("#contentContainer").length) {
		$("#contentContainer").width(mw);
	}
	
	if ($("#activeBlocks").length) {
		$("#activeBlocks").width(mw);
	}
	
	// height
	var wh = $(window).height();
	var hh = $("#header").height();
	var fh = $("#footer").height();
	var mh = (wh-(hh+fh+1));
	var pch = $('#pagecontent').height();
	var pbh = $("#pagebody").height();
	var lrh = $("#leftrail").height();
	var rrh = $("#rightrail").height();
	var ach = $("#actualContent").height();
	
	if (pbh < lrh) {
		pbh = lrh;
		ach = lrh;
	} else if (pbh < rrh) {
		pbh = rrh;
		ach = rrh;
	}
	
	if (ach <= mh) {
		if (pbh <= mh) {
			$("#pagebody").height(mh+18);
			pbh = mh+18;
		}
	} else {
		$("#pagebody").height(ach+68);
		pbh = ach+50;
	}
	
	if (MY_CONTROLLER == 'dashboard') {
		$("#footer").css('top', pbh+fh-5);
	} else {
		$("#footer").css('top', pbh+fh+30);
	}
//	alert('mh = ' + mh + "\n" + 'pch = ' + pch + "\n" + 'pbh = ' + pbh);
//	if ($(".viewTable").length) {
//		$(".viewTable").width(mw-5);
//	}
}

function fixMaxSize() {
			$('img').each(function() {		

		if( $(this).css('max-width') != 'none' || $(this).css('max-height') != 'none' ) {

			max_width = $(this).css('max-width').replace(/[^0-9]/g, '');
			max_height = $(this).css('max-height').replace(/[^0-9]/g, '');		
			if( $(this).width() > max_width || $(this).height() > max_height ) {
				if( (max_width / $(this).width()) < (max_height / $(this).height()) ) {
					if ($(this).height() > max_height) {
						$(this).css('height', Math.round($(this).height() * (max_width / $(this).width())));
					}
					if ($(this).width() > max_width) {
						$(this).css('width', max_width);
					}
				} else {
					if ($(this).width() > max_width) {
						$(this).css('width', Math.round($(this).width() * (max_height / $(this).height())));
					}
					if ($(this).height() > max_height) {
						$(this).css('height', max_height);
					}
				}

			}
		}
	});

}

$(document).ready(function() {
	MY_CONTROLLER = $("body").attr('id');
	MY_METHOD = $("body").attr('class');
	
	$.ajaxSetup({timeout: 10000000});
	
	if ($("input[name=QAID]")) {
		MY_QAID = $("input[name=QAID]").val();
	}
	
	//$(".rounded, .block").corners();
	$(".dialog").dialog({
		autoOpen: false
	});
	$("#loginDialog").resizable().draggable({containment: '#pagebody'});

	fixMaxSize();
	
	if ($(".qaForm")) {
		$(".qaForm").ajaxForm(function(r) {
			if (r == 1) {
				$(".qaForm").resetForm();
				$("#qaBody").hide();
				doLoad();
				clearPreTags();
				clearPreLcs();
				clearPreUrls();
			} else {
				$("#qaFeedback").html(r).show();
				setTimeout('$("#qaFeedback").html("").hide();', 5000);
			}
			
			return false;
		});
		
		$(".qalink").click(function(e) {
			$("#qaBody").toggle();
			e.preventDefault();
		});
		
		$("#qaCancelBtn").click(function() {
			$("#qafeedback").html('');
			$(".qaForm").resetForm();
			$("#qaBody").hide();

			clearPreTags();
			clearPreLcs();
		});
		
		if ($("#qafeedback").empty()) {
			$("#qaBody").hide();
		}
		
		if ($("#preTagsContainer").length) {
			loadPreTags();
		}
		
		if ($("#preLcsContainer").length) {
			loadPreLcs();
		}
		
		if ($("#preUrlsContainer").length) {
			loadPreUrls();
		}
	}	

	if ($("#fltrTag").length) {
		var myFltrTag = $("#fltrTag").val();
				
		if (myFltrTag == '') {
			$("#clearFltrTag").hide();
		}
				
		$("#fltrTag").keyup(function() {
			var myVal = $(this).val();
				
			if (myVal == '') {
				$("#clearFltrTag").hide();
			} else {
				$("#clearFltrTag").show();
			}
				
			clearTimeout(loadTimer);
			loadTimer = setTimeout('doLoad();', 1000);
		});
				
		$("#clearFltrTag").click(function(e) {
			$("#fltrTag").val('');
			$("#clearFltrTag").hide();
			doLoad();
			e.preventDefault();
		});
	}
			
	if ($("#orderBy").length) {
		$("#orderBy").change(function() {
			doLoad();
		});
	}
		
	if ($("#fltrDate").length) {
		$("#fltrDate").change(function() {
			doLoad();
		});
	}

	if ($("#fltrSite").length) {
		$("#fltrSite").change(doLoad);
	}

	if ($("#fltrType").length) {
		$("#fltrType").change(doLoad);
	}

	if ($("#fltrSize").length) {
		$("#fltrSize").change(doLoad);
	}

	if ($(".thumbUploader").length) {
		$(".thumbUploader").each(function() {
			var rel = $(this).attr('rel');
			$("#" + rel + "_urlContainer").hide();
			$(this).find(".urlLink").click(function(e) {
				$("#" + rel + "_useFile").val('0');
				$("#" + rel + "_upldContainer").hide();
				$("#" + rel + "_urlContainer").show();
				e.preventDefault();
			});
			
			$(this).find(".upldLink").click(function(e) {
				$("#" + rel + "_useFile").val('1');
				$("#" + rel + "_upldContainer").show();
				$("#" + rel + "_urlContainer").hide();
				e.preventDefault();
			});
		});
	}
	
	$(".clickTag").unbind('click').click(function(e) {
		var myTag = $(this).attr('href');
		if (myTag !== '') {
			clickTag(myTag);
		}
		e.preventDefault();
	});
	$(".actag").autocomplete({source: '/actags.php', delay: 100});
	
	$(".dpicker").datepicker();
	$("input[type=button],input[type=submit],input[type=reset]").button();
	
	$(".newTypeSelect").each(function() {
		var rel = $(this).attr('rel');
		var val = $(this).val();
		
		if (val !== 'NEW') {
			$(".newTypeContainer[rel=" + rel + "]").hide();
		} else {
			$(".newTypeContainer[rel=" + rel + "]").show();
		}
		
		$(this).unbind('change').change(function() {
			if ($(this).val() == 'NEW') {
				$(".newTypeContainer[rel=" + rel + "]").show();
			} else {
				$(".newTypeContainer[rel=" + rel + "]").hide();
			}
		});
	});
	
	$(".newSizeSelect").each(function() {
		var rel = $(this).attr('rel');
		var val = $(this).val();
		
		if (val !== 'NEW') {
			$(".newSizeContainer[rel=" + rel + "]").hide();
		} else {
			$(".newSizeContainer[rel=" + rel + "]").show();
		}
		
		$(this).unbind('change').change(function() {
			if ($(this).val() == 'NEW') {
				$(".newSizeContainer[rel=" + rel + "]").show();
			} else {
				$(".newSizeContainer[rel=" + rel + "]").hide();
			}
		});
	});

	$("#leftrail dl dt a").each(function(e) {
		var rel = $(this).parent().attr('rel');
		
		if (rel != 'none') {
			img = new Image();
			img.src = '/images/navigation/' + rel + '-open.jpg';
		}
	});
	
	$("#leftrail dl dt a").click(function(e) {
		var rel = $(this).parent().attr('rel');
		
		if (rel != 'none') {
			var myClass = $(this).parent().attr('class').split('_');

			if (myClass[1] !== 'open') {
				$(this).parent().attr('class', $(this).parent().attr('class') + '_open');
			} else {
				$(this).parent().attr('class', rel);
			}
			$("#" + rel + "_menu").toggle();
			e.preventDefault();
		}
	});
	
	fixContentSize();
	setTimeout('fixContentSize()', 100);
});

$(window).resize(fixContentSize);
