// JavaScript Document

$j(document).ready(
		function() {
			
			if(currentSelectedMediaTypeId) {
				$j("#MediaTypeMediaTypeId option").each(
						function () {
							var value = $j(this).val();
							
							if(value == currentSelectedMediaTypeId) {
								$j(this).attr('selected', 'selected');
							}
						}
				);
			} else {
				$j("#MediaTypeMediaTypeId option").each(
						function () {
							var value = $j(this).val();
							
							if(value == 0) {
								$j(this).attr('selected', 'selected');
							}
						}
				);
				
			}
			
			//set sort asc or desc
			$j('.header_link.sort_key').each(
					function() {
						var this_class = $j(this).attr('class');
						var parts = this_class.split(' ');
						var sortKey = parts[2];
						if (sortKey == "sort_desc") {
							label = 'pagination_sort_desc.png';
						} else {
							label = 'pagination_sort_asc.png';
						}
						var target = $j('.header_link.sort_key.'+sortKey+' a');
						$(document.createElement("img")).attr({src: '/img/portfolio/'+label}).appendTo(target);
					}
			);
			
		
			$j('.ourWorkDescriptionContainer').click(
						function() {
							var pid = $j(this).parent().attr('id').split('_')[2];
							url = 'http://'+window.location.hostname + '/';
							
							window.location.href= url + 'portfolio/details/' + pid;
							//loadAjaxContent('/portfolio_items/details/' + pid);
						}
			);
			
			
			$j('#MediaTypeMediaTypeId').change( 
					function() {
						filterResults($j(this).val());
					}
			);
			
		}
);


function filterResults(typeID) {
   url = 'http://'+window.location.hostname + '/';
   path = window.location.pathname;
	parts = path.split('/');
	if(parts.length < 3 || parts[2] == "") {
		baseURL = url + 'portfolio/index';
	} else {
		baseURL = url + parts[1] + '/' + parts[2];
	}
	
    window.location.href= baseURL + '/filter:MediaType.media_type_id='+typeID;
	
}


function updateFilterSize(height) {
	$j("#filterContainer").css('height', height + 'px');
	$j("#filterContainer").css('z-index', '9999');
}

