function slideShowResize() {
  $('#slideshow').height($('#wrapper').height());
}

function initFrontPageSlideShow() {
  var slideshowElement = $('#slideshow');
  if(slideshowElement.length) {
    slideShowResize();
    $(window).resize(function() {
      slideshowElement.find("div:not(div.active)").css({opacity: 0.0});
      slideShowResize();
    });
    setInterval("slideSwitch()", 5000);
  }
}

function slideSwitch() {
  var slideshowElement = $('#slideshow');
  var active = $('#slideshow div.active');
  var next = active.next();
  if (!next.length) {
    next = slideshowElement.find('div:first:not(div.active)');
  }
  if (next.length) {
    next.addClass('active');
    active.removeClass('active');
    next.animate({opacity: 1.0}, 1000, function() {
      active.css({opacity: 0.0});
    });
  }
}

$(document).ready(function() {
  initFrontPageSlideShow();
	var obj_div_menu = $('div.menu'); var SUBMENU = false;
	// menu shadow
	obj_div_menu.find('>ul>li:gt(0)').hover(
	    function() { obj_div_menu.find('span.hover').css( { left: $(this).position().left - 3 }).show(); },
	    function() { obj_div_menu.find('span.hover').hide(); }
	);
	obj_div_menu.find('>ul>li:eq(0)').hover(
	    function() { obj_div_menu.find('span.hover-first').show(); },
	    function() { obj_div_menu.find('span.hover-first').hide(); }
	)
	// sub menu
	.find('a').hover(
	    function() { SUBMENU = false; obj_div_menu.find('div.sub').show(); },
	    function() { setTimeout(function() { if (!SUBMENU) obj_div_menu.find('div.sub').hide(); }, 50)}
	);
	obj_div_menu.find('div.sub').hover(
	    function() { SUBMENU = true; $(this).show(); },
	    function() { $(this).hide(); }
	);
	// search input
	obj_div_menu.find('input.text').bind({
		focus: function(){
			if ($(this).val() == valueSearch) $(this).val('');
		},
		blur: function(){
			if ($(this).val() == '') $(this).val(valueSearch);
		}
	});

	obj_layout = $('body.main div.layout');
	obj_layout.height($(window).height());
	$(window).resize( function(){ 
    obj_layout.height( $(window).height() ); 
  });

	var params = {}; var flashVars = {};

	if ($('#slides').length > 0 && $('#slides').attr('url') != '')
	{
		params = {wmode:'opaque', allowScriptAccess:'always' };
		flashVars = { dataPath: $('#slides').attr('url') };
		swfobject.embedSWF('/swf/slideViewer.swf', 'slides', '100%', '100%', '6', '/swf/expressInstall.swf', flashVars, params);
	}

	if ($('#video').length > 0 && $('#video').attr('url') != '')
	{
		params = {wmode:'transparent', allowScriptAccess:'always' };
		flashVars = { video_url: $('#video').attr('url') };
		swfobject.embedSWF('/swf/videoViewer.swf', 'video', '235', '180', '6', '/swf/expressInstall.swf', flashVars, params);
	}

	$('#twitter').getTwitter({
		userName: 'PBGlobal',
		numTweets: 1,
		loaderText: loadingTwitts,
		slideIn: false
	});

	// cycle plugin on main
	if ($('#slider').length > 0)
	{
		$('#slider').after('<div id="nav">').cycle({ 
			fx:     'scrollUp', 
			speed:   1000, 
			timeout: 6000, 
			pager:  '#nav' 
		});
	}

	obj_lng_select = $('#footer div.select');
	// languages dropdown on main
	obj_lng_select.find('span').click(function(event){
		event.stopPropagation(); $(this).next().toggle();
	});
	obj_lng_select.find('ul li a').click(function(event){
		event.stopPropagation(); $(this).parent().parent().hide();
	});
	$(document).click(function(){ obj_lng_select.find('ul').hide(); });

	$.reject();
});
