// If jQuery didn't load from the CDN use the local file
!window.jQuery && document.write(unescape('%3Cscript src="/js/jquery-1.6.4.min.js"%3E%3C/script%3E'));

// bookmark site
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
} // onclick="bookmarksite(document.title,document.location);return false;"

// toggle open close button
function toggle_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'none')
	  e.style.display = 'block';
   else
	  e.style.display = 'none';
}

// addthis customizer
var addthis_config = {ui_cobrand:"Morphix", ui_use_addressbook:"true", data_track_clickback:"true", ui_508_compliant:"true"}

// jquery
$(document).ready(function(){
	// dropmenu
	var timeout    = 500;
	var closetimer = 0;
	var ddmenuitem = 0;
	
	function dropmenu_open()
	{  dropmenu_canceltimer();
	   dropmenu_close();
	   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}
	
	function dropmenu_close()
	{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}
	
	function dropmenu_timer()
	{  closetimer = window.setTimeout(dropmenu_close, timeout);}
	
	function dropmenu_canceltimer()
	{  if(closetimer)
	   {  window.clearTimeout(closetimer);
		  closetimer = null;}}
	
	$(document).ready(function() {  $('#dropmenu > li, #sidemenu > li').bind('mouseover', dropmenu_open)
	   $('#dropmenu > li, #sidemenu > li').bind('mouseout',  dropmenu_timer)});
	
	document.onclick = dropmenu_close;
	// color every other row
	$('table tr:odd').addClass('odd');
	// save onstate
	loc = location.href.substring(7);
	loc = loc.substring(loc.indexOf("/"));
	var i = loc.indexOf("#");
	if (i > -1) loc = loc.substring(0, i);
	var i = loc.indexOf("?");
	if (i > -1) loc = loc.substring(0, i);
    if (loc == '/' && !($("#nav a[href='" + loc + "']").length)) loc = "/index.php";
	$("#topnav a[href='" + loc + "']").addClass('on');
	$("#sidemenu a[href='" + loc + "']").closest("li").addClass('on');
	// preload images
	$.fn.preload = function() {
		this.each(function(){
			$('<img/>')[0].src = this;
		});
	}
	$(['']).preload();
	// entire block clickable
	$(".pane-list li").click(function() {
    	window.location=$(this).find("a").attr("href");return false;
	});
	// hover color transition
	$(".first a").hover(function() {
		$(this).animate({ backgroundColor:"#00aadd"}, 600);
	},function() {
		$(this).animate({ backgroundColor:"#303030"}, 400);
	});
	// placeholder
	if(!$.support.placeholder) {
	  var active; 
	  try { 
	  	active = document.activeElement; 
	  } catch(e) { 
	  	active = $('body');
	  }
      $("input:text").add("textarea").focus(function () {
         if ($(this).attr('placeholder') != '' && $(this).attr('placeholder') != undefined && $(this).val() == $(this).attr('placeholder')) {
            $(this).val('').removeClass('hasPlaceholder');
         }
      }).blur(function () {
         if ($(this).attr('placeholder') != '' && $(this).attr('placeholder') != undefined && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
            $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
         }
      });
      $("input:text").add("textarea").blur();
      $(active).focus();
      $("form:eq(0)").submit(function() {
         $(":text.hasPlaceholder").add("textarea.hasPlaceholder").val('');
      });
	}
});

$(function() {
    $('#slideshow-home #slide-content').cycle({
        fx: 'fade',
        timeout: 6500,
        speed: 1000,
        next:   '#slidenav-right', 
    	prev:   '#slidenav-left' 
    });
});

(function($) {
    $('#slideshow #slide-content')
    .cycle({
        fx: 'fade',
        timeout: 6500,
        speed: 1000,
        cssAfter: "class='on'",
        cssBefore: "class=''",
        after: onTransition,
        sync: true
/* 		pager: '#navigation' */

    });
    
        $('#slideshow li a').click(function() {
        var slideIndex = parseInt($(this).closest("li").attr("data-slideIndex"));
        var slide = $(this);
		getSlide(slide,slideIndex);
        return false;
    });
    
    function getSlide(slide,slideIndex) {
            $('#slideshow #slide-content').cycle(slideIndex);
        $('#slideshow li a').each(function(){
        	$(this).removeClass("on");
        	});
        $(slide).addClass("on");
        return false;
    }

    
/*
    function onAfter(curr,next,opts){
    
    };
*/
})(jQuery);
    function onTransition() {
    var index = $(this).attr('data-slideIndex');
    $('#slideshow li a').removeClass('on');
    $('#slideshow li[data-slideIndex="'+index+'"] a').addClass('on');
};

$(function(){
	$('#topnav a').next('ul').hover(
		function(){
			$(this).prev('a').css("background-image", "url(/image/arrow-up.png)"); 
		},
		function(){
			$(this).prev('a').css("background-image", "url(/image/arrow-down.png)"); 
		}
	);	
	

	$('#topnav a.sub').bind('mouseover mouseout mousemove', function(event) {
		if (event.type == 'mouseover' || event.type == 'mousemove') {
$(this).css("background-image", "url(/image/arrow-up.png)");
		}
 
		if (event.type == 'mouseover') {
$(this).css("background-image", "url(/image/arrow-up.png)");
		}
 
		if (event.type == 'mouseout') {
$(this).css("background-image", "url(/image/arrow-down.png)"); 
		}
		});

});


/*
$(document).ready(function(){
 $("a[@href^='http']").attr('target','_blank');
}); 
*/
RepeatingOperation = function(op, yieldEveryIteration) {
var count = 0;
var instance = this;
this.step = function(args) { 
if (++count >= yieldEveryIteration) { 
count = 0;
setTimeout(function() { op(args); }, 1, [])
return;
}
op(args); 
}; 
};


(function($){
/*
	$('.flashvars').each(function(index) {
   		alert(index + ': ' + $(this).text());
	});
*/
	$('object').attr('allowfullscreen','true');
})(jQuery);

function embedVideo(video){
        var flashvars = {};
		flashvars.video = "http://morphtec.com/file/videos/"+video+".flv";
		flashvars.uiControls = "PlayPause|TimeElapsed|Seek|Volume|MuteUnmute|FullScreen";
		flashvars.autoPlay = true;
		flashvars.loop = false;
		flashvars.loopDelay = 5000;
		flashvars.returnToStart = false;
		flashvars.volume = 0;
        var params = {};
        var attributes = {};
        attributes.id = video;
        attributes.allowFullScreen = true;
        swfobject.embedSWF("http://morphtec.com/include/plugin/flashvars/videoPlayer.swf", "altContent1", "320", "180", "9.0.28", false, flashvars, params, attributes);
}
