//delegate.js
/**
 * Creates a new method attached to the object specified. Inside the method,
 * {this} will reference {obj}.
 * @param {Object} obj The object to attach the method to.
 * @param {Function} method The method to attach to the object.
 * @return {Function} The function attached to the object.
 */
function Delegate(obj, method) {
	return function () {
		method.apply(obj, arguments);
	};
}
//init.js
/**
 * Initialization script for all application components
 */

$(document).ready(function() {
	if(isCompany) {
		var lang = $('#lg').html();
		if(lang == 'tr') {
			$('.main-navigation').append('<li class="top"><a href="/kurumsal">kurumsal</a><ul><li><a href="/kurumsal/listapplications">iş başvuruları</a></li><li><a href="/kurumsal/jobpostingform">iş ilanı ver</a></li><li><a href="/kurumsal/settingsform">seçenekler</a></li></ul></li>');
		}
		if(lang == 'en') {
			$('.main-navigation').append('<li class="top"><a href="/kurumsal">corporate</a><ul><li><a href="/kurumsal/listapplications">applications</a></li><li><a href="/kurumsal/jobpostingform">job posting</a></li><li><a href="/kurumsal/settingsform">options</a></li></ul></li>');
		}
	}
	
	if (typeof MainMenu == "function") { new MainMenu(".main-navigation"); }
		
	$(".tabbed-module").each(function (index, module) {
		if (typeof TabbedModule == "function") { new TabbedModule(module); }
	});
	
	$(".flash-player > a.flash-link, .flash-player > object").each(function (index, element) {
		if (typeof FlashPlayer == "function") { new FlashPlayer(element); }
	});

	if($(document.body).hasClass("home-page")) {
		if (typeof CompanyViewer == "function") { new CompanyViewer(".company-viewer .companies"); }
		if (typeof Poll == "function") { new Poll(".poll-results .poll-options"); }
	}

	if($(document.body).hasClass("content-page")) {
		if (typeof ExpandableModule == "function") { new ExpandableModule(".expandable-sidebar-module"); }
		
		if (typeof SemanticForm == "function") { new SemanticForm("form.form-section"); }
	}

	if($(document.body).hasClass("results-page")) {
		if (typeof ExpandableModule == "function") { new ExpandableModule(".expandable-sidebar-module"); }
		
		if (typeof RefineSearch == "function") { new RefineSearch(".expandable-refine-filter"); }
	}
	/*
	$('.branch-results-page .resultlisting').each(function (index, element) {
		if (typeof Map == "function") {
			new Map(element, '.branch-result .branch-gmap', Map.USETEXT);
			
			// Map is disabled, enable map in search results by uncommenting this line.
			//new Map(element, '.search-result', Map.USEINDEX);
		}
	});
	*/
		
	$(".brand-header .service-concept").each(function (index, element) {
		if ($('a', element).attr('href') != '#') {
			return;
		}
		
		$(element).click(function(e) {
			$(".brand-header .service-concept").each(function (index, element) {
				$(document.body).removeClass($(element).attr("id"));
			});
			$(document.body).addClass($(this).attr("id"));
		});
	});
	
	
	$('.sidebar-map a, .job-search .tabs li:nth-child(2) a').click(function() {
		$('.search-results-page .resultlisting').each(function (index, element) {
			if (typeof Map == "function") {
				Map.addLocation(0, 52.1, 4.4);
				Map.addLocation(1, 52.2, 4.5);
				Map.addLocation(2, 52.3, 4.6);
				
				new Map(element, '.search-result', Map.USEINDEX);
			}
		});
	})
	
	//new Styleguide();
});
//c02-dropdownmenu.js
function MainMenu(element) {
	this._element = $(element);
	this._buildMenu();
}

MainMenu.prototype = {
	_element: null,
	
	_buildMenu: function () {
		this._element.find("ul").each(function (index, element) {
			element = $(element);
			if (element.parent("li").hasClass("active")) {
				element.parent("li").addClass("has-children");
			} else {
				element.hide().parent("li").addClass("has-children");
			}
		});
		
		this._element.find("li").hover(function () {
			// 'this' is the 'li' element.
			$(this).addClass('active');
			$(this).parent("ul").parent("li").addClass("child-selected");
			$(this).children("ul").show();
		}, function () {
			// 'this' is the 'li' element.
			$(this).removeClass('active');
			$(this).parent("ul").parent("li").removeClass("child-selected");
			$(this).children("ul").hide();
		});
	}
};

