$(document).ready(function() {
	
	$('#showTools').click(function() {
		$('#hasProducts').hide();
		$('#hasAccessories').hide();
		$('#hasTools').show();
		$('#hasAssignments').hide();
		$('#hasReferences').hide();
		
	    return false;
	});
	
	$('#showAccessories').click(function() {
		$('#hasProducts').hide();
		$('#hasAccessories').show();
		$('#hasTools').hide();
		$('#hasAssignments').hide();
		$('#hasReferences').hide();		
	
	    return false;
	});	
	
	$('#showProducts').click(function() {
		$('#hasProducts').show();
		$('#hasAccessories').hide();
		$('#hasTools').hide();
		$('#hasAssignments').hide();
		$('#hasReferences').hide();		
		
	    return false;
	});
	
	$('#showAssignments').click(function() {
		$('#hasProducts').hide();
		$('#hasAccessories').hide();
		$('#hasTools').hide();
		$('#hasAssignments').show();
		$('#hasReferences').hide();		
		
	    return false;
	});
	
	$('#showReferences').click(function() {
		$('#hasProducts').hide();
		$('#hasAccessories').hide();
		$('#hasTools').hide();
		$('#hasAssignments').hide();
		$('#hasReferences').show();		
		
	    return false;
	});		
	
	$('#categories-big').show();
	$('#categories-small').hide();
	
	$('#show-pane-small').click(function() {
		
		$('#show-pane-big').removeClass("active");
		$('#show-pane-small').addClass("active");
		$('#categories-big').hide();
		$('#categories-small').show();
		
	    return false;
	});

	$('#show-pane-big').click(function() {
		
		$('#show-pane-small').removeClass("active");
		$('#show-pane-big').addClass("active");
		$('#categories-big').show();
		$('#categories-small').hide();
		
	    return false;
	});	
	
	if (jQuery.url.param("context") != null && jQuery.url.param("context") != "home") {
		$('body').removeClass("home");
		$('body').addClass("downloads");		
	}
	else if (jQuery.url.param("act") != null){
		$('body').removeClass("home");
		$('body').addClass("products");	
	}	
	else if (jQuery.url.param("favOid") != null) {
		$('body').removeClass("home");
		$('body').addClass("products");		
	} else {
		var currentURL = window.location.toString();

		if(currentURL.match(/bookmark\.do$/)) {
			$('body').removeClass("home");
			$('body').addClass("products");				
		}
	}
	
	var $jobListingInfo = $('#job-listing .job-info');
	var $jobListingInfoToggle = $('#job-listing .job-info .job-info-head .toggle');
	var $jobListingInfoContent = $('#job-listing .job-info .toggle-item');
	
	$jobListingInfoContent.hide();
	$jobListingInfoContent.addClass('closed');
	
	$jobListingInfoToggle.each(function(i) {
		$(this).delegate('a', 'click', function(event) {
			var $jobListingInfoContentCurrent = $jobListingInfoContent.eq(i);
			event.preventDefault();
			
			if ($jobListingInfoContentCurrent.hasClass('open')) {
				$jobListingInfoContentCurrent.slideUp(500,function() {
					$(this).css('display','none');
				});
				$jobListingInfoContentCurrent.removeClass('open');
				$jobListingInfoContentCurrent.addClass('closed');
				$(this).css('background','transparent url(../img/toggle.png) no-repeat scroll 100% 0px');
			} else {
				$jobListingInfoContentCurrent.slideDown(500,function() {
					$(this).css('display','block');
				});
				$jobListingInfoContentCurrent.removeClass('closed');
				$jobListingInfoContentCurrent.addClass('open');
				$(this).css('background','transparent url(../img/toggle.png) no-repeat scroll 100% -27px');
			}
		});
	});
});

function addToCompare (oid) {
	var url = '/catalogue/catalogue.do?act=compareBookmarks&action=add&oid=' + oid;
	$.get(url);
}

function addToDownloadlist (oid) {
	var url = '/catalogue/bookmark.do?act=mediaDownload&action=add&mediaoid=' + oid;
	$.get(url);
}

function refreshFancyBox (oid) {
	var url = '/catalogue/catalogue.do?act=showInfoblock&forward=showInfoblock&favOid=' + oid;

	$.colorbox({href:url});
}

function addItemToCart(url) {
	$.get(
		url,
		function() {
			$('#merkzettel').load("/catalogue/bookmark.do?act=refreshBookmarkList");
		}
	);
}

function pager (pagerUrl, page, favOid) {
	var url = pagerUrl+'&favOid='+favOid+'&page='+page;
	var container = $("#detail-overview").parent();
	container.load(url);
}

function openFancybox3D (oid) {
	var url = '/catalogue/catalogue.do?act=showCad&forward=showCad&favOid=' + oid;
	$.fancybox({
		'titleShow' : false,
		'type': 'iframe',
		'href': url,
		'overlayColor': '#fff',
		'overlayOpacity': 0.8,
		'width': 940,
		'height': 690,
		'hideOnOverlayClick':true,
		'showCloseButton': true,
		'padding': 8
	});
}

function openFancyInfobox (oid) {
	var url = '/catalogue/catalogue.do?act=showInfoblock&forward=showInfoblock&favOid=' + oid;
	$.colorbox({ href: url});
}	

function filter(propertyId, propertyValue, oldValue, oid) {
	var act = "search";
	var propertyType = 3;
	var container = $("#powersearch").parent();
	
	if ( propertyValue == '_nonselect_') {
		var action = "deSelectProperty";
		container.load("/catalogue/catalogueSearchByProperty.do", {oid: oid, forward: "searchProductByPropertyBox", act: act, propertyType: propertyType, action: action, propertyId: propertyId, propertyValue: oldValue } );
	}
	else {
		var action = "selectProperty";
		container.load("/catalogue/catalogueSearchByProperty.do", {oid: oid, forward: "searchProductByPropertyBox", act: act, propertyType: propertyType, action: action, propertyId: propertyId, propertyValue: propertyValue } );
	}
}
