// site specific javascript

	// html 5 elements
	document.createElement("article");
	document.createElement("footer");
	document.createElement("header");
	document.createElement("hgroup");
	document.createElement("section");
	document.createElement("nav");
	document.createElement("datalist");

if(!jQuery.browser.safari)
{
	jQuery(document).ready(function(){
		behavior_binder();
	});
}
else
{
	jQuery(window).load(function(){
		behavior_binder();
	});
}


/*
Binds behaviors
** can be re-run whenever there are DOM changes
*/
function behavior_binder(){
	
	/* HOMEPAGE DL */	
	jQuery('div.inline_pager_list').inlinePager({
		numItems:1,
		autoPage: 8000
	});
	
	/* HEADER SEARCH FORM */
	jQuery('#searchsubmit').attr('value','');
	
	/* MENU FUNCTIONS */
	
	jQuery('#menu-nbcuni-menu li a').each(function(){
		jQuery(this).parent('li').addClass('menu-item-'+jQuery(this).html().toLowerCase().replace(/[^[a-z0-9]/,''));
	})
	jQuery('.menu-item').append('<span class="menu-item-bg"></span>');
	jQuery('.menu-item-investorrelations a').attr('target','_blank');
	jQuery('.menu-item-careers a').attr('target','_blank');
	jQuery('.menu-item-shopping a').attr('target','_blank');
	
	/* PHOTO GALLERY */
	jQuery('div#photoGallery').slideProjector({keep_state:0,preload_images: false});
	
	/* MEDIA UPLOAD (in pods) */
	jQuery('.dropme').live('click',function(){
		jQuery(this).parents('.image_manager_block').html('');
	})
	
	/* PROJECT IMAGES */
	jQuery('#project_thumb_images li a').click(function(){
		var this_img = jQuery(this).attr('rel');
		jQuery('#project_main_images li').hide();
		jQuery('#'+this_img).show();
		jQuery('#project_thumb_images .selected').removeClass('selected');
		jQuery(this).parent('li').addClass('selected');
	})
	
	/* PAGINATION FOR POD LIST */	
	set_pagination();
	jQuery('.pod_selector_selection').click(function(){
		jQuery('#pod_selector li').removeClass('selected');
		jQuery(this).parent('li').addClass('selected');
		var this_letter = jQuery(this).attr('rel');
		var this_name = jQuery(this).html();
		if(this_letter == 'all'){
			var list_array = {};
			for(var i in data_json){
			    if(data_json.hasOwnProperty(i)){
			        for(var j in data_json[i]){
			            list_array[j]=data_json[i][j];
			        }
			    }
			}
			var keys = [];
			var l2 = {};
			for (var l in list_array){
				if(list_array[l]['show_first'] == 1){
					l2[list_array[l]['slug']]=list_array[list_array[l]['slug']];
				}
			}
			for (var slug in list_array){
				    keys.push(slug);
			}
			keys.sort();
			for (var i = 0; i < keys.length; i++){
				l2[keys[i]]=list_array[keys[i]];
			}
			list_array = l2;
			
		}else{
			var list_array = data_json[this_letter];
		}
		jQuery('#pod_list').parents('.simplePagerContainer').remove();
		jQuery('#pod_list').remove();
		jQuery('#pod_selector_container').after('<ul id="pod_list" class="items pod_list_paginated"></ul>');
		jQuery('#pod_list').prepend(return_pod_landing_list_item(list_array));
		jQuery('.section_list_title_number').html(jQuery('#pod_list li').length);
		jQuery('.section_list_title_business').html(this_name);
		if(this_letter == 'all'){
			set_pagination();
		}else{
			var num_items = jQuery('.pod_list_paginated li').length;
			set_pagination(num_items)
		}
	})
	
	/* SEARCH RESULTS */
	
	jQuery(".search_engine_results").quickPager({
		pagerLocation:"after",
		pageSize:6,
		itemsPerRow:1,
		pageCounterTemplate: 'Showing [$$START]-[$$END] of [$$TOTAL]'
	});
}
/*
TRIGGERS THE PAGINATION ON THE GIVEN ELEMENT
*/
function set_pagination(num_itms){
	var num_items=arguments[0]!==undefined?arguments[0]:9;
	jQuery(".pod_list_paginated").quickPager({
		pagerLocation:"after",
		pageSize:num_items,
		itemsPerRow:3,
		pageCounterTemplate: 'Showing [$$START]-[$$END] of [$$TOTAL]',
		paginationShowLimit: 5
	});
}
function return_pod_landing_list_item(list_array){
	
	var list_item = '';
	for(i in list_array){
		list_item += '<li id="'+list_array[i]['slug']+'" class="item">';
		if(list_array[i]['this_link'] != 'contact_us'){
			list_item += '<a class="item_image" href="/'+list_array[i]['this_link']+'/'+list_array[i]['slug']+'" title="'+list_array[i]['name'] +'">';
			list_item += '<img alt="'+list_array[i]['name'] +'" src="'+list_array[i]['strImageSrc']+'" height="'+list_array[i]['iImageHeight']+'" width="'+list_array[i]['iImageWidth'] +'" /></a>';
		}
		list_item += '<span class="item_text">';
		if(list_array[i]['this_link'] != 'contact_us'){
			list_item += '<h2><a href="'+list_array[i]['this_link']+'/'+list_array[i]['slug']+'" title="'+list_array[i]['name'] +'">'+list_array[i]['name'] +'</a></h2>';
			if(list_array[i]['this_pod'] == 'people'){
				list_item += '<p class="item_job_title">'+list_array[i]['job_title']+',</p>';
				list_item += '<p class="item_company">'+list_array[i]['company']+'</p>';
			}
			if((list_array[i]['this_pod'] == 'company')||(list_array[i]['this_pod'] == 'citizenship')){
				list_item += '<p class="item_excerpt">'+list_array[i]['excerpt']+'</p>';
			}
		}else{
			list_item += '<h2><a href="'+list_array[i]['this_link']+'/'+list_array[i]['slug']+'" title="'+list_array[i]['name'] +'">'+list_array[i]['company'] +'</a></h2>';
			list_item += '<p class="item_contact_name">'+list_array[i]['name']+'</p>';
			list_item += '<p class="item_job_title">'+list_array[i]['job_title']+'</p>';
			list_item += '<p class="item_contact_info"><span class="item_contact_info_phone">';
			list_item += list_array[i]['phone'];
			list_item += '</span> | <span class="item_contact_info_email"><a href="mailto:'+list_array[i]['email']+'">'+list_array[i]['email']+'</a></span></p>';
					
		}
		
		list_item += '</span></li>';
	}
	return list_item;
}

// JavaScript Document
