//flash: youtube
var pwp_ytubevars			= "&amp;border=0";
var pwp_w					= 190-(4*2);
var pwp_h					= 154;

//toggle sitemap
function toggle_sitemap(){ 
	$('ul.sitemap').slideToggle('normal', function(){ 
		$(document).scrollTop(document.body.scrollHeight); 
	}); 
};


//form: contacts
var pwp_form_contacts_options	= {
	path:	pwp_template_dir+"_content/process_contacts.php",
	check:	[
		{id:'#name', 		alert:'Please insert your name. Thank You.'},
		{id:'#email', 		rules:[{exp:false, alert:'Please insert your email. Thank You.'},{exp:String($.p.CONST.REGEX_EMAIL), alert:'Your email address is invalid.'}]},
		{id:'#message',		alert:"Please write your message. Thanks You."}
	],
	init:	function(item)		{ 
				$('p.comment').html("The contact form is being sent. Please wait...");
				item.hide('normal');
			},
	end:	function(item, data){
				$('p.comment').html(data);
				item.show('normal');
			}
}


//form: careers
var pwp_form_careers_options	= {
	path:	pwp_template_dir+"_content/process_careers.php",
	check:	[
		{id:'#name'},{id:'#address'},{id:'#postalcode'},{id:'#city'},{id:'#nationality'},		
		{id:'#email', rules:[{exp:false, alert:'Please insert your email. Thank You.'},{exp:String($.p.CONST.REGEX_EMAIL), alert:'Your email address is invalid.'}]},
		{id:'#birthdate'},{id:'#telephone'},
		
		{id:'#academic-background'},{id:'#school-university'},{id:'#course'},{id:'#graduationyear'},{id:'#othercourses'},
		
		{id:'#languages'},{id:'#workexperience'},{id:'#functions'}
	],
	init:	function(item)		{ 
				$('p.comment').html("The careers form information is being processed. Please wait...");
				item.hide('normal');
			},
	end:	function(item, data){
				$('p.comment').html(data);
				item.show('normal');
			},
	upload:	{vars:{label:'oops', path:pwp_root+'/temp.upload/'}}
}


//form: newsletter
var pwp_form_mail_options 		= {
	path:	pwp_template_dir+"_content/process_mailinglist.php",
	check:	[
		{id:'.name', alert:'Please insert your name. Thank You.'},
		{id:'.email', rules:[{exp:String($.p.CONST.REGEX_EMAIL), alert:'Your email address is invalid.'}]}
	]
}


//form: partners
var pwp_form_partners_options 	= {
	path:	pwp_template_dir+"_content/process_partners.php",
	check:	[
		{id:'.email', rules:[{exp:false, alert:'Please insert your email. Thank You.'},{exp:String($.p.CONST.REGEX_EMAIL), alert:'Your email address is invalid.'}]},
		{id:'.pass', alert:'Please insert your password. Thank You.'}
	]
}



$(document).ready(function(){  

	//HEADER: tab function to 2 elements of #header ul.nav + subnav clicks
	$('a[href=#newsletter], a[href=#partners]').pTabs();
	$('ul.img a:eq(0)').click(function(){ $(this).pBookmark();	});
	$('ul.img a:eq(1)').click(function(){ $.p.send(); 			});
	$('ul.img a:eq(2)').click(function(){ window.print();		});
	
	


	//NAVIGATION: slows speed on navigation | hides flash video to display media subcategory's children */
	//$('.pwp_nav_ssf').pwpNavSlide(600); //less speed
	$('.pwp_nav_ssf li.cat-item-5').mouseover(function(){ $('#sidebar object').hide(); })
								   .mouseout(function()	{ $('#sidebar object').show(); });



	//CONTENT: form validation/submission initialization
	$('form#f-mail').pForm(pwp_form_mail_options);						   
	$('form#f-partners').pForm(pwp_form_partners_options);						   
	$('form#contacts').pForm(pwp_form_contacts_options);
	$('form#careers').pForm(pwp_form_careers_options);

	

	//SIDEBAR: news slideshow
	$.getJSON(pwp_template_dir+"_content/process_sidebar.php", function(data){
		var a = []; 
		
		for(i in data){
			var n = Math.floor(i/3);
			a[n] = (a[n] != undefined? a[n] : "")+'<li>'+data[i].html+'</li>';
		}

		$('#sidebar>ul>li:eq(1)>ul').pRefresh({data:a, time:8000, change:function(obj){
			obj.find('img').hide().load(function(){ $(this).pResize({width:90}).show();	})
		}})
	});
	
	//slideToggle for sidebar modules and content related posts.
	//adds double click to sidebar h2 links
	$('#sidebar h2, ul.related h2').click(function(){ $(this).next().slideToggle('slow'); return false; })
						    	   .find('a').each(function(){ 
										$(this).dblclick(function(){ window.open($(this).attr('href')); })
											   .attr('title', 'Double click to open this link: '+$(this).attr('href')) 
									});	



	//FOOTER: hides sitemap and vb-links onload
	$('ul.sitemap, li.linkcat>ul').hide();
	
	
 	//FLASH [MISC]: header banner
	swfobject.embedSWF(pwp_template_dir+"_content/swf/header.swf", "banner", "966", "190", "9.0.0", null, pwp_flashvars, {menu:'false', wmode:'transparent'});
	//flash: youtube channel
	swfobject.embedSWF("http://www.youtube.com/cp/vjVQa1PpcFOXYutSlWnOMcpCZ7GWc65YzvsFDAFq1B4="+pwp_ytubevars, "youtube", pwp_w, pwp_h, "9.0.0");
	
	
	//add wrapper for image background purposes [middle]
	$('#sidebar, #content, #navigation').wrapAll('<div id="jContentBG"></div>');
	//adds wrapper to frontpage for centering float content
	$('#post-586').wrap('<div class="outer post-586"><div class="inner"></div></div>');
})

