// JavaScript Document
var xml_url = '';

function selectPpl(obj) {
	var url = obj.attr("href");
	var el = obj;
	
	
	if($(this).parent().hasClass("active")){
		el.parent().parent().parent().next(".show_people_profile").hide();
		el.parent().removeClass("active");
		el.parent().parent().parent().find(".show_people_profile").hide();
	}else {

		el.parent().parent().parent().find(".active").removeClass("active");
		el.parent().addClass('active');

		$.get(url, function(data){
			el.parent().parent().parent().find(".show_people_profile").html(data).show();
		});
		
		return false;
	}
	
	return false;
}

$(document).ready(function() {
		xml_url = $('#url_base').val() + "xml/index/";

		$("#principals ul li a, #directors ul li a, #project_directors ul li a, #ass-directors ul li a").click(function(){
			var url = $(this).attr("href");
			var el = $(this);
			
			
			myArr = window.location.href.split('#');
			
			if($(this).parent().hasClass("active")){
				el.parent().parent().parent().next(".show_people_profile").hide();
				$(this).parent().removeClass("active");
				el.parent().parent().parent().find(".show_people_profile").hide();
				
				var parentId = el.parent().parent().parent().attr('id');
				
				window.location.href = myArr[0] + '#' + parentId;
			}else {
				el.parent().parent().parent().find(".active").removeClass("active");
				$(this).parent().addClass('active');

				$.get(url, function(data){
					el.parent().parent().parent().find(".show_people_profile").html(data).show();
				});
			
				window.location.href = myArr[0] + '#' + el.parent().attr('id').replace('ppl', '');
				
				return false;
			}
			
			return false;
			
		});	

		
$(".sub-dd li a").click(function(){ 
	
	clear_filter_cotainer();
	
	$(".selected-filters span#selected-dd").html($(this).text()+' <a href="javascript:;" onclick="delete_tag(this);" class="dd" rel="'+$(this).attr("rel")+'" ></a>').css('display', 'inline-block');
	
	$('#sector_filter_li').show();
		
	var desingId = 'undefined';
	$('.selected-filters a.dd').each(function () {
		desingId = $(this).attr('rel');	
	});
	
	var sectorId = 'undefined';
	$('.selected-filters a.s').each(function () {
		sectorId = $(this).attr('rel');	
	});
	
	
	var projectTypeId = 'undefined';
	$('.selected-filters a.pt').each(function () {
		projectTypeId = $(this).attr('rel');	
	});
	
	switch (desingId) {
		case '3':
			$('ul.sub-pt li').hide();
			$('#sector_filter_li').hide();
			
			$('ul.sub-pt li a[rel="125"]').parent().show();
			$('ul.sub-pt li a[rel="126"]').parent().show();
			
		break;
		case '4': 
			$('ul.sub-pt li').hide();
			$('#sector_filter_li').hide();
			
			$('ul.sub-pt li a[rel="127"]').parent().show();
			$('ul.sub-pt li a[rel="128"]').parent().show();
		break;
		case '5':
			$('ul.sub-pt li').hide();
			$('#sector_filter_li').hide();
			
			$('ul.sub-pt li a[rel="129"]').parent().show();
			$('ul.sub-pt li a[rel="130"]').parent().show();
		break;
		default: 
			$('ul.sub-pt li').show();
			$('#sector_filter_li').show();
			
			$('ul.sub-pt li a[rel="125"]').parent().hide();
			$('ul.sub-pt li a[rel="126"]').parent().hide();
			$('ul.sub-pt li a[rel="127"]').parent().hide();
			$('ul.sub-pt li a[rel="128"]').parent().hide();
			$('ul.sub-pt li a[rel="129"]').parent().hide();
			$('ul.sub-pt li a[rel="130"]').parent().hide();
		break;
	}
	
		
	// when there is no flash intalled
	if(!FlashDetect.installed)
	{
		var porfolio_url = $('#url_base').val()+'portfolio/index/1/';
		if(desingId == 'undefined')
		{
			desingId = 0;
		}
		if(sectorId == 'undefined')
		{
			sectorId = 0;
		}
		if(projectTypeId == 'undefined')
		{
			projectTypeId = 0;
		}
		
		porfolio_url = porfolio_url + desingId +"/"+sectorId+"/"+projectTypeId;
		document.location = porfolio_url;
		//alert(porfolio_url);
	}
	else
	{
		update_flash(xml_url+""+escape(desingId)+"/"+escape(sectorId)+"/"+escape(projectTypeId));
		return false;
	}
		
});	
		
$(".sub-s li a").click(function(){ 
	
	clear_filter_cotainer();
	
	
	//var url_filters = $('#url_base').val() + "xml/";
	
	/*if($(".selected-filters").find('a.dd')){
		var desingId = $(".selected-filters").find('a.dd').attr('rel');
	} else {
		var desingId = 0;
	}
	
	if($(".selected-filters").find('a.pt')){
		var projectTypeId = $(".selected-filters").find('a.pt').attr('rel');
	} else {
		var projectTypeId = 0;
	} */
	
	$(".selected-filters span#selected-s").html($(this).text()+' <a href="javascript:;" onclick="delete_tag(this);" class="s" rel="'+$(this).attr("rel")+'" ></a>').css('display', 'inline-block');
	
	var desingId = 'undefined';
	$('.selected-filters a.dd').each(function () {
		desingId = $(this).attr('rel');	
	});
	
	var sectorId = 'undefined';
	$('.selected-filters a.s').each(function () {
		sectorId = $(this).attr('rel');	
	});
	
	
	var projectTypeId = 'undefined';
	$('.selected-filters a.pt').each(function () {
		projectTypeId = $(this).attr('rel');	
	});
	
	/*jQuery.getJSON(url_filters + 'update_filters/' + desingId + '/' + sectorId + '/' + projectTypeId, function(json) {
		
	});*/
	
	switch (desingId) {
		case '3':
			$('ul.sub-pt li').hide();
			$('#sector_filter_li').hide();
			
			$('ul.sub-pt li a[rel="125"]').parent().show();
			$('ul.sub-pt li a[rel="126"]').parent().show();
			
		break;
		case '4': 
			$('ul.sub-pt li').hide();
			$('#sector_filter_li').hide();
			
			$('ul.sub-pt li a[rel="127"]').parent().show();
			$('ul.sub-pt li a[rel="128"]').parent().show();
		break;
		case '5':
			$('ul.sub-pt li').hide();
			$('#sector_filter_li').hide();
			
			$('ul.sub-pt li a[rel="129"]').parent().show();
			$('ul.sub-pt li a[rel="130"]').parent().show();
		break;
		default: 
			$('ul.sub-pt li').show();
			$('#sector_filter_li').show();
			
			$('ul.sub-pt li a[rel="125"]').parent().hide();
			$('ul.sub-pt li a[rel="126"]').parent().hide();
			$('ul.sub-pt li a[rel="127"]').parent().hide();
			$('ul.sub-pt li a[rel="128"]').parent().hide();
			$('ul.sub-pt li a[rel="129"]').parent().hide();
			$('ul.sub-pt li a[rel="130"]').parent().hide();
		break;
	}
	
	// when there is no flash intalled
	if(!FlashDetect.installed)
	{
		var porfolio_url = $('#url_base').val()+'portfolio/index/1/';
		if(desingId == 'undefined')
		{
			desingId = 0;
		}
		if(sectorId == 'undefined')
		{
			sectorId = 0;
		}
		if(projectTypeId == 'undefined')
		{
			projectTypeId = 0;
		}
		
		porfolio_url = porfolio_url + desingId +"/"+sectorId+"/"+projectTypeId;
		document.location = porfolio_url;
		//alert(porfolio_url);
	}
	else
	{
		update_flash(xml_url+""+escape(desingId)+"/"+escape(sectorId)+"/"+escape(projectTypeId));
		return false;
	}
		
});	

$('#filter_russian').click(function () {	
	
	clear_filter_cotainer();
	
	
		$(".selected-filters span#selected-ru").html('Ð Ð¾Ñ?Ñ?Ð¸Ñ? <a href="javascript:;" onclick="delete_tag(this);" class="ru" rel="'+$(this).attr("rel")+'" ></a>').css('display', 'inline-block');
		
		var desingId = 'undefined';
		$('.selected-filters a.dd').each(function () {
			desingId = $(this).attr('rel');	
		});
		
		var sectorId = 'undefined';
		$('.selected-filters a.s').each(function () {
			sectorId = $(this).attr('rel');	
		});
		
		
		var projectTypeId = 'undefined';
		$('.selected-filters a.pt').each(function () {
			projectTypeId = $(this).attr('rel');	
		});
		
		update_flash(xml_url+""+escape(desingId)+"/"+escape(sectorId)+"/"+escape(projectTypeId) + '/1');
		return false;
	}
)

$(".sub-pt li a").click(function(){ 
	
	clear_filter_cotainer();
	
	
	
	/*if($(".selected-filters").find('a.dd')){
		var desingId = $(".selected-filters").find('a.dd').attr('rel');
	} else {
		var desingId = 0;
	}
	
	if($(".selected-filters").find('a.s')){
		var sectorId = $(".selected-filters").find('a.s').attr('rel');
	} else {
		var sectorId = 0;
	} */
	
	$(".selected-filters span#selected-pt").html($(this).text()+' <a href="javascript:;" onclick="delete_tag(this);" class="pt" rel="'+$(this).attr("rel")+'" ></a>').css('display', 'inline-block');
	
	var desingId = 'undefined';
	$('.selected-filters a.dd').each(function () {
		desingId = $(this).attr('rel');	
	});
	
	var sectorId = 'undefined';
	$('.selected-filters a.s').each(function () {
		sectorId = $(this).attr('rel');	
	});
	
	
	var projectTypeId = 'undefined';
	$('.selected-filters a.pt').each(function () {
		projectTypeId = $(this).attr('rel');	
	});
	
	switch (desingId) {
		case '3':
			$('ul.sub-pt li').hide();
			$('#sector_filter_li').hide();
			
			$('ul.sub-pt li a[rel="125"]').parent().show();
			$('ul.sub-pt li a[rel="126"]').parent().show();
			
		break;
		case '4': 
			$('ul.sub-pt li').hide();
			$('#sector_filter_li').hide();
			
			$('ul.sub-pt li a[rel="127"]').parent().show();
			$('ul.sub-pt li a[rel="128"]').parent().show();
		break;
		case '5':
			$('ul.sub-pt li').hide();
			$('#sector_filter_li').hide();
			
			$('ul.sub-pt li a[rel="129"]').parent().show();
			$('ul.sub-pt li a[rel="130"]').parent().show();
		break;
		default: 
			$('ul.sub-pt li').show();
			$('#sector_filter_li').show();
			
			$('ul.sub-pt li a[rel="125"]').parent().hide();
			$('ul.sub-pt li a[rel="126"]').parent().hide();
			$('ul.sub-pt li a[rel="127"]').parent().hide();
			$('ul.sub-pt li a[rel="128"]').parent().hide();
			$('ul.sub-pt li a[rel="129"]').parent().hide();
			$('ul.sub-pt li a[rel="130"]').parent().hide();
		break;
	}
	
	// when there is no flash intalled
	if(!FlashDetect.installed)
	{
		var porfolio_url = $('#url_base').val()+'portfolio/index/1/';
		if(desingId == 'undefined')
		{
			desingId = 0;
		}
		if(sectorId == 'undefined')
		{
			sectorId = 0;
		}
		if(projectTypeId == 'undefined')
		{
			projectTypeId = 0;
		}
		
		porfolio_url = porfolio_url + desingId +"/"+sectorId+"/"+projectTypeId;
		document.location = porfolio_url;
		//alert(porfolio_url);
	}
	else
	{	
		update_flash(xml_url+""+escape(desingId)+"/"+escape(sectorId)+"/"+escape(projectTypeId));
		return false;
	}
		
});	



	$("#Design_Discipline").change(function(){
		update_flash(xml_url+""+$(this).val()+"");
		return false;
	}); 
	
});

function update_flash(url){
	getFlashMovie("myContent1").updateFlash(url);
}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function clear_filter_cotainer() {
	$('div.selected-filters span').each(function () {
		$(this).html('').hide();
	});
}

function delete_tag(el) {

	$(el).parent().html('').hide();
	
	var desFilterObject = $(".selected-filters span#selected-dd").find('a.dd');
	var sFilterObject = $(".selected-filters span#selected-s").find('a.s');
	var ptFilterObject = $(".selected-filters span#selected-pt").find('a.pt');
	var ruFilterObject = $(".selected-filters span#selected-ru").find('a.ru');
	
	if(desFilterObject.attr('class')){
		var desingId = desFilterObject.attr('rel');
	} else {
		var desingId = 0;
		$('#sector_filter_li').show();
		$('ul.sub-pt li').show();
		
		$('ul.sub-pt li a[rel="125"]').parent().hide();
		$('ul.sub-pt li a[rel="126"]').parent().hide();
		$('ul.sub-pt li a[rel="127"]').parent().hide();
		$('ul.sub-pt li a[rel="128"]').parent().hide();
	}
	
	if(sFilterObject.attr('class')){
		var sectorId = sFilterObject.attr('rel');
	} else {
		var sectorId = 0;
	}
	
	if(ptFilterObject.attr('class')){
		var projectTypeId = ptFilterObject.attr('rel');
	} else {
		var projectTypeId = 0;
	}
	
	if(ruFilterObject.attr('class')){
		var projectRu = 1;
	} else {
		var projectRu = 0;
	}
	
	update_flash(xml_url+""+desingId+"/"+sectorId+"/"+projectTypeId+ (projectRu == 1 ? '/1' : ''));
	return false;
}
