
// TO BE TABS FUNCTIONS

function slideit(i) {

	$('.header-pic , .header-description , .items div img').click(function(){
		clearTimeout(control_timeout);
	});

	$('#tab' + i).click();

	if (i==1) {
		var control_timeout = setTimeout("slideit(3)", 5000);
	} else if (i==2) {
		var control_timeout = setTimeout("slideit(1)", 5000);
	} else if (i==3) {
		var control_timeout = setTimeout("slideit(2)", 5000);
	}

}

function html11(VideoAddr) {
	$("#vb2").html('<iframe width="540" height="290" src="' + VideoAddr + '" frameborder="0" style="z-index:100;" id="HeaderOne" allowfullscreen></iframe>');
}

function html22(VideoAddr) {
	$("#vb1").html('<iframe width="540" height="290" src="' + VideoAddr + '" frameborder="0" style="z-index:100;" id="HeaderTwo" allowfullscreen></iframe>');
}

function html33(VideoAddr) {
	$("#vb3").html('<iframe width="540" height="290" src="' + VideoAddr + '" frameborder="0" style="z-index:100;" id="HeaderThr" allowfullscreen></iframe>');
}

// CAROUSEL FUNCTIONS

function mycarousel_initCallback(carousel) {
    carousel.buttonNext.bind('click', function() { carousel.startAuto(0); });
    carousel.buttonPrev.bind('click', function() { carousel.startAuto(0); });
    carousel.clip.hover(function() { carousel.stopAuto(); }, function() { carousel.startAuto();
    });
};

// INTRO FLASH OPEN

function onClickProducto(content){

	var player = 'iframe';
	var title = '';

	Shadowbox.open({
		content:    content,
		player:     player,
		title:      title,
		height:     700,
		width:      970
	});
}

/*

// ADD CLOSE BOTTON

	function moveCloseLink(){ 
			var cb=document.getElementById('sb-nav-close'); 
			var tb=document.getElementById('sb-wrapper'); 
			if(tb) tb.appendChild(cb); 
	}

*/

// PLAY INTRO FLASH

function showIntro(){

	var n = 0;

	if (!$.cookie('valor')==''){
		var n = $.cookie('valor');
		n++;
		
		$.cookie('valor', n , { path: '/' } );
	}else{
		$.cookie('valor', 1 , { path: '/' } );
	}

	if (parseInt(n) <= 3 ) {
		Shadowbox.init({
	 // onOpen: moveCloseLink,
			overlayOpacity: 0.8
		}, function(){					
				setTimeout('onClickProducto("/swf/SER2.swf")',1000);
				setTimeout('Shadowbox.close()',15000);
			});
	}

}


function wherewe(){

	var mb = document.forms["zipSearch"].program.value ;

	if ( mb === 'all' ) self.location.reload();

	document.forms["zipSearch"].submit();

}


// TO BE TABS

function homeSlider(){

 var tabContainers = $('#headers > div');

 $('#headers ul.tabNavigation a').click(function () {
 
// event.preventDefault();
 
	tabContainers.hide().filter(this.hash).show();

 var a = $(this).attr("id");

  switch(a){

   case "tab1":
     $(this).addClass('firstSEL');
     $("#tab2").removeClass('middleSEL');
     $("#tab3").removeClass('endSEL');
   break;

   case "tab2":
     $(this).addClass('middleSEL');
     $("#tab1").removeClass('firstSEL');
     $("#tab3").removeClass('endSEL');

   break;

   case "tab3":
     $(this).addClass('endSEL');
     $("#tab1").removeClass('firstSEL');
     $("#tab2").removeClass('middleSEL');
   break;

   default: $(this).addClass('firstSEL');

 }
  return false;
}).filter(':first').click();
 
}


// VIDEO GALLERY GET CONTENT AND TITLE FROM YOUTUBE XML

function parseXmlas(xml) {

	$("#yt_content").html($(xml).find("content").text().substr(0,231));
	$("#yt_title").html($(xml).find("title").text().substr(0,50));

}

// VIDEO GALLERY - LOAD VIDEO AND TITLE WHITE DESC.

function changeVideo(viene) {

	$('#player').attr('src', viene);

	var id_video = viene.replace("http://www.youtube.com/embed/", "");

	$.get('/youtube.php?idv=' + id_video , function(data) {
		parseXmlas(data);
	});

	$("#FBKSHARE").click(function () {
		window.open("http://www.facebook.com/share.php?u="+window.location,"Facebook","scrollbars=yes, width=750,height=600")
	})

	$("#TWSHARE").click(function () {
		window.open("http://twitter.com/intent/tweet?text=Read this "+ window.location,"Twitter","scrollbars=yes, width=600,height=385");
	})
/* * */
}

// SLIDE PARTNERS

function slidesPart() {
 $('#slides').slides({
   preload: true,
   play: 5000,
   generateNextPrev: false,
   hoverPause: false
 });
}

// ADD CHROME CASCADE STYLE SHEET FILE

function include(Src) {

	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	var is_IE9    = navigator.userAgent.toLowerCase().indexOf('msie 9') > -1;
	var is_IE8    = navigator.userAgent.toLowerCase().indexOf('msie 8') > -1;
	var is_IE7    = navigator.userAgent.toLowerCase().indexOf('msie 7') > -1;
	var is_IE6    = navigator.userAgent.toLowerCase().indexOf('msie 6') > -1;

	if(is_chrome){

			var sc = document.createElement('link');
			sc.type = 'text/css';
			sc.href = Src;
			sc.rel = 'stylesheet';
			document.getElementsByTagName('head')[0].appendChild(sc);
			sc = null;

			$("#zip_code").css("margin-top", "20px");
			$("#zip_code").css("border-left", "1px solid #d1d1d1");
			$('#text_desc_vid_gal').css('margin-top','255px');

		}

	//	.css('border','1px solid blue');

	if (is_IE9) {
		$('#tabla_videos').css('max-width','590px');
		$('#tabla_videos').css('margin-left','15px');
	}

	if (is_IE8) {
		$("#iecrossclass").prev('div').css("border","1px solid red");
		$("#iecrossclass").css("max-height","18px");
		$("#iecrossclass").css("max-height","18px");
		$('#iecrossclass div').css("max-height","18px");
		$('#iecrossclass ul').css("max-height","18px");
	}

	if (is_IE7) {
	}

	if (is_IE6) {
	}		
		
}

// ACCORDION MENU ( PROGRAMS )

function initMenu() {
  $('#AccordionList ul').hide();
//$('#AccordionList ul:first').show();
  $('#AccordionList li h2').click(
    function(){
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))){
        $('#AccordionList ul:visible').slideDown('normal');
        checkElement.slideUp('normal');
        return false;
      }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))){
		$('html, body').animate({ scrollTop: '630px' }, 'slow');
        $('#AccordionList ul:visible').slideUp('normal');
        checkElement.slideDown('normal');
        return false;
      }
    }
  );
}

// CHANGE COLOR ACCORDION TITLE

function addingClassHover(src){
	$("#AccordionList li h2").removeClass('activedtitle');
	$(src).addClass('activedtitle');
}

function shareF() {
  window.open('http://www.facebook.com/share.php?u='+window.location,'','');
}

function shareT() {
  window.open('http://twitter.com/intent/tweet?text=Ser National&url='+window.location,'','')
}

/*

Prototype Function Style

window.onload = function(){

	$("#navi").mouseover(function() {

		var b = window.location.pathname;
		var c = b.substr(1);
		var d = c.split('/');

		if (d[0]) {
			if (d[0].length == '') {
				$('.home').removeClass('active');
			} else {
				$('.' + d[0]).removeClass('active');
			}
		} else {
			
			$('.home').removeClass('active');
		}
	});

// UNSET ACTIVE WHILE NAV MOUSE OVER 

	$("#navi").mouseout(function() {

		var b = window.location.pathname;
		var c = b.substr(1);
		var d = c.split('/');
		if (d[0]) {
			if (d[0].length == '') {
				$('.home').addClass('active');
			} else {
				$('.' + d[0]).addClass('active');
			}
		} else {
			$('.home').addClass('active');
		}
	});
}
*/

// SET ACTIVE LINK BY CURRENT PAGE NAME 

$(function () {

	// navi & submenu automatic active

	var b = window.location.pathname;
	var c = b.substr(1);
	var d = c.split('/');

	if (d[0]) {
		if (d[0].length == '') {
			$('.home').addClass('active');
		} else {
			$('.' + d[0]).addClass('active');
		}
	} else {
		$('.home').addClass('active');
	}
/* 
	if(d[0]=='affiliation-information') {
		$('.become-an-affiliate').addClass('active');
	}
 */
	$('a[href$="' + c + '"]').addClass('this-one-choose');

	
	// media center > publications press releases > tabs

	$("#tabA").click(function(){
		$("#tabA").css("background","#ffffff");
		$("#tabB").css("background","#efefef");
		$("#press").css("display","none");
		$("#publi").css("display","block");
	})
	$("#tabB").click(function(){
		$("#tabA").css("background","#efefef");
		$("#tabB").css("background","#ffffff");
		$("#press").css("display","block");
		$("#publi").css("display","none");
	})


	// news > go back & print the detail

	$("#thenews").click(function(){
		history.back(-1);
	});

	$("#theplot").click(function(){
		var div4print = document.getElementById("printbox");
		var NewWindow = window.open("", "NewWindow");
			NewWindow.document.write(div4print.innerHTML);
			NewWindow.document.close();
			NewWindow.print();
			NewWindow.close();
	});

	include('/css/chrome.css');
	
});

// CLEAR INPUT

function vaciar(nmd){
   nmd.value="";
}




