// JavaScript Document

$(document).ready(
		function() {
			
			if(currentSelectedMediaTypeId) {
				$("#MediaTypeMediaTypeId option").each(
						function () {
							var value = $(this).val();
							
							if(value == currentSelectedMediaTypeId) {
								$(this).attr('selected', 'selected');
							}
						}
				);
			} else {
				$("#MediaTypeMediaTypeId option").each(
						function () {
							var value = $(this).val();
							
							if(value == 0) {
								$(this).attr('selected', 'selected');
							}
						}
				);
				
			}
			
			//set sort asc or desc
			$('.header_link.sort_key').each(
					function() {
						var this_class = $(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 = $('.header_link.sort_key.'+sortKey+' a');
						$(document.createElement("img")).attr({src: '/img/portfolio/'+label}).appendTo(target);
					}
			);
			
		
			$('.ourWorkDescriptionContainer').click(
						function() {
							var pid = $(this).parent().attr('id').split('_')[2];
							url = 'http://'+window.location.hostname + '/';
							
							window.location.href= url + 'portfolio/details/' + pid;
							//loadAjaxContent('/portfolio_items/details/' + pid);
						}
			);
			
			
			$('#MediaTypeMediaTypeId').change( 
					function() {
						filterResults($(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) {
	$("#filterContainer").css('height', height + 'px');
	$("#filterContainer").css('z-index', '9999');
}


