// Copyright 2010 AVISIAN

// prevent empty searches
function site_search() {
  var value = document.f.q.value.replace(/^\s+$/, '')
  if (value != '') {
    document.f.submit()
  } else {
    alert("Please provide one or more search terms in the search field.")
  }
}

// handle article previews
var article_status = new Array()
function article_preview(id) {
  if(article_status[id] != 'on') {
    $('#a_' + id).fadeIn(500)
    $('#on_' + id).hide()
    $('#off_' + id).show()
    article_status[id] = 'on'
  } else {
    $('#a_' + id).fadeOut(500)
    $('#off_' + id).hide()
    $('#on_' + id).show()
    article_status[id] = 'off'
  }
}

// the following requires jquery, jquery.tools and flowplayer:

function getFlashMovieObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(movieName);
    }
}

// enable resource overlays
$(function() {
  $(".area_display img[rel]").overlay({
    effect: 'apple',
    speed: 500,
    // when overlay is opened, load our player
    onLoad: function() {
      // flowplayer(0).load();
    },
    // when overlay is closed, unload our player
    onClose: function() {
      // flowplayer(0).unload();
    }
  });
});

// set overlay effect default
$.extend($.tools.overlay.conf, {
  effect: 'apple',
  api: true,
  speed: 300 // snappy
});

function textSwap(idorclass,classname,start_text,end_text){
  if (idorclass == "class")
    var text_element = document.getElementsByClassName(classname)[0];
  else
    var text_element = document.getElementById(classname);
  if (text_element.value == start_text)
    text_element.value = end_text
}
function jTextSwap(element, start_text, end_text){
  if (jQuery(element).val() == start_text)
    jQuery(element).val(end_text);
}
function closeFeaturesWindow(id) {
  jQuery("#article_share_" + id).hide('blind', 300);
  jQuery("#share_email_" + id).empty();
  jQuery("#share_email_" + id).hide();
  jQuery("#article_share_spinner_" + id).show();
}

function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
}
function limitTextCount(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function scrollTo(id){
  $('html,body').animate({scrollTop: $("#"+id).offset().top},'fast');
}

$(document).ready(function() {
  $(".markItUp").markItUp(mySettings);
});


