/* js goes here */ 

var BD = (function() {

	return {

		init : function() {

		},

		Camps : {

			init : function(baseURL, type, page, perPage){

				if (arguments.length) {
					this.baseURL = baseURL;
					this.type = type;
					this.page = page;
					this.perPage = perPage;
				}

				$('#list_current_page').change(function(e) {
					var i = $(e.target);
					if (parseInt(i.attr('value'))) {
						BD.Camps.page = parseInt(i.attr('value'));
						BD.Camps.search();
					} else {
						i.attr('value', BD.Camps.page);
					}
				});

				$('#list_next_page').click(function(e) {
					if (BD.Camps.page < parseInt($('#list_total_pages').html())) { 
						BD.Camps.page++;
						BD.Camps.search();
					}
					return false;
				});

				$('#list_prev_page').click(function(e) {
					if (BD.Camps.page > 1) { 
						BD.Camps.page--;
						BD.Camps.search();
					}
					return false;
				});

				$('#list_pagination_select').change(function(e) {
					var sel = $('#list_pagination_select');
					BD.Camps.page = 1;

					BD.Camps.perPage = $(this).val();
					BD.Camps.search();
				});
			},

			search : function() {

				$.ajax({
					url : BD.Camps.baseURL + 'main/camp_search',
					type: 'POST',
					data : {
						type : BD.Camps.type,
						perPage : BD.Camps.perPage,
						page : BD.Camps.page
					},
	
					success : function(data) {
						$('div.main_right').html(data);
						BD.Camps.init();
					}
				});
			}		
		},


		News : {

			init : function(baseURL, type, page, perPage){

				if (arguments.length) {
					this.baseURL = baseURL;
					this.type = type;
					this.page = page;
					this.perPage = perPage;
				}

				$('#product-search-link').unbind().click(function(e) {
					BD.News.filter = $('#bd-product-search').attr('value');
					BD.News.search();
					return false;
				});

				$('#list_current_page').change(function(e) {
					var i = $(e.target);
					if (parseInt(i.attr('value'))) {
						BD.News.page = parseInt(i.attr('value'));
						BD.News.search();
					} else {
						i.attr('value', BD.News.page);
					}
				});

				$('#list_next_page').click(function(e) {
					if (BD.News.page < parseInt($('#list_total_pages').html())) { 
						BD.News.page++;
						BD.News.search();
					}
					return false;
				});

				$('#list_prev_page').click(function(e) {
					if (BD.News.page > 1) { 
						BD.News.page--;
						BD.News.search();
					}
					return false;
				});

				$('#list_pagination_select').change(function(e) {
			
					var sel = $('#list_pagination_select');
					BD.News.page = 1;
			
					BD.News.perPage = sel.attr('options')[sel.attr('selectedIndex')].value;
					BD.News.search();
				});
			},

			search : function() {
				
				$.ajax({
					url : BD.News.baseURL + 'main/news_search',
					type: 'POST',
					data : {
						type : BD.News.type,
						perPage : BD.News.perPage,
						page : BD.News.page
					},
	
					success : function(data) {
						$('div.main_right').html(data);
						BD.News.init();
					}
				});
			}		
		},


		Projects : {

			init : function(baseURL, type, page, perPage){

				if (arguments.length) {
					this.baseURL = baseURL;
					this.type = type;
					this.page = page;
					this.perPage = perPage;
				}
				
				$('#product-search-link').unbind().click(function(e) {
					BD.Projects.filter = $('#bd-product-search').attr('value');
					BD.Projects.search();
					e.preventDefault();
				});

				$('#list_current_page').change(function(e) {
					var i = $(e.target);
					if (parseInt(i.attr('value'))) {
						BD.Projects.page = parseInt(i.attr('value'));
						BD.Projects.search();
					} else {
						i.attr('value', BD.Projects.page);
					}
				});

				$('#list_next_page').click(function(e) {
					if (BD.Projects.page < parseInt($('#list_total_pages').html())) { 
						BD.Projects.page++;
						BD.Projects.search();
					}
					e.preventDefault();
				});

				$('#list_prev_page').click(function(e) {
					if (BD.Projects.page > 1) { 
						BD.Projects.page--;
						BD.Projects.search();
					}
					e.preventDefault();
				});

				$('#list_pagination_select').change(function(e) {
			
					var sel = $('#list_pagination_select');
					BD.Projects.page = 1;
			
					BD.Projects.perPage = sel.attr('options')[sel.attr('selectedIndex')].value;
					BD.Projects.search();
				});
			},

			search : function() {
				$.ajax({
					url : BD.Projects.baseURL + 'main/projects_search',
					type: 'POST',
					data : {
						type : BD.Projects.type,
						perPage : BD.Projects.perPage,
						page : BD.Projects.page
					},
					
					success : function(data) {
						$('div.projects').html(data);
						BD.Projects.init();
					}
				});
			}		
		},


		Careers : {

			init : function(baseURL, type, page, perPage){

				if (arguments.length) {
					this.baseURL = baseURL;
					this.type = type;
					this.page = page;
					this.perPage = perPage;
				}

				$('#product-search-link').unbind().click(function(e) {
					BD.Careers.filter = $('#bd-product-search').attr('value');
					BD.Careers.search();
					return false;
				});

				$('#list_current_page').change(function(e) {
					var i = $(e.target);
					if (parseInt(i.attr('value'))) {
						BD.Careers.page = parseInt(i.attr('value'));
						BD.Careers.search();
					} else {
						i.attr('value', BD.Careers.page);
					}
				});

				$('#list_next_page').click(function(e) {
					if (BD.Careers.page < parseInt($('#list_total_pages').html())) { 
						BD.Careers.page++;
						BD.Careers.search();
					}
					return false;
				});

				$('#list_prev_page').click(function(e) {
					if (BD.Careers.page > 1) { 
						BD.Careers.page--;
						BD.Careers.search();
					}
					return false;
				});

				$('#list_pagination_select').change(function(e) {
			
					var sel = $('#list_pagination_select');
					BD.Careers.page = 1;
			
					BD.Careers.perPage = sel.attr('options')[sel.attr('selectedIndex')].value;
					BD.Careers.search();
				});
			},

			search : function() {

				$.ajax({
					url : BD.Careers.baseURL + 'main/careers_search',
					type: 'POST',
					data : {
						type : BD.Careers.type,
						perPage : BD.Careers.perPage,
						page : BD.Careers.page
					},
	
					success : function(data) {
						$('div.main_right').html(data);
						BD.Careers.init();
					}
				});
			}		
		},
		
		Products : {

			init : function(baseURL, type, division, page, perPage) {
				if (arguments.length) {
					this.baseURL = baseURL;
					this.type = type;
					this.division = division;
					this.page = page;
					this.perPage = perPage;
				}

				$('#product-search-link').unbind().click(function(e) {

					if ($('#bd-product-search').attr('value') != BD.Products.filter) {
						BD.Products.filter = $('#bd-product-search').attr('value');
						BD.Products.page = 1;
						BD.Products.search();
					}

					return false;
				});

				$('#list_current_page').change(function(e) {
					var i = $(e.target);
					if (parseInt(i.attr('value'))) {
						BD.Products.page = parseInt(i.attr('value'));
						BD.Products.search();
					} else {
						i.attr('value', BD.Products.page);
					}
				});

				$('#list_next_page').click(function(e) {
					if (BD.Products.page < parseInt($('#list_total_pages').html())) { 
						BD.Products.page++;
						BD.Products.search();
					}
					return false;
				});

				$('#list_prev_page').click(function(e) {
					if (BD.Products.page > 1) { 
						BD.Products.page--;
						BD.Products.search();
					}
					return false;
				});

				$('#list_pagination_select').change(function(e) {
			
					var sel = $('#list_pagination_select');
					BD.Products.page = 1;
			
					BD.Products.perPage = sel.attr('options')[sel.attr('selectedIndex')].value;
					BD.Products.search();
				});
			},

			search : function() {

				$.ajax({
					url : BD.Products.baseURL + 'main/products_search',
					type: 'POST',
					data : {
						type : BD.Products.type,
						division: BD.Products.division,
						filter : BD.Products.filter,
						perPage : BD.Products.perPage,
						page : BD.Products.page
					},
	
					success : function(data) {
						$('div.main_right').html(data);
						BD.Products.init();
					}
				});
			}
		}
	};

}());


$(document).ready(function(e) {

	$('#bd-print').click(function(e) {
		window.print();
		return false;
	});

	$('.filter_menu_top a').click(function(e) {

		$('.filter_menu').attr('class', 'filter_menu');
		$('.filter_menu').addClass($(e.target).attr('class'));

		return false;
	});

	$('#bd-product-search-link').click(function(e) {

		return false;
	});

});
