// TOP NAVIGATION
var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);});

document.onclick = jsddm_close;



//mainNav = function() {
//	$("#nav li").bind("mouseenter",function(){
//                this.className += "_over over";
//	}).bind("mouseleave",function(){
//                this.className = this.className.replace("_over over", "");
//	});
//}


// FEATURE SLIDER TOGGLE
var theInt = null;
		var $crosslink, $navthumb, $spanlink;
		var curclicked = 0;
		
		theInterval = function(cur){
			clearInterval(theInt);
			
			if( typeof cur != 'undefined' )
				curclicked = cur;
			
			$crosslink.removeClass("active-thumb");
			$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
			
			theInt = setInterval(function(){
				$crosslink.removeClass("active-thumb");
				$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
				curclicked++;
				if( 4 == curclicked )
					curclicked = 0;
				
			}, 7000);
		};
		
		$(function(){
			
			$("#main-photo-slider").codaSlider();
			
			$navthumb = $(".nav-thumb");
			$crosslink = $(".cross-link");
			$spanlink = $("span-link");
			
			$navthumb
			.click(function() {
				var $this = $(this);
				theInterval($this.parent().attr('href').slice(1) - 1);
				return false;
			});
			
			theInterval();
		});
		


// SLIDE ANCHOR
$(document).ready(function() {
 function filterPath(string) {
    return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
 }
$('a[href*=#]').each(function() {
	if ( filterPath(location.pathname) == filterPath(this.pathname) && location.hostname == this.hostname && this.hash.replace(/#/,'') ) {
		var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
		var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if ($target) {
				var targetOffset = $target.offset().top;
					$(this).click(function() {
				    $('html, body').animate({scrollTop: targetOffset}, 1200);
					return false;
					});
				}
			}
		});
	});



// SEARCH FOCUS
$(document).ready(function() {
	jQuery("input#search-field").focus(function() {if(jQuery(this).val() == "Search Point of View") {jQuery(this).val('');}}); 
	jQuery("input#search-field").blur(function() {if(jQuery(this).val() == "") {jQuery(this).val('Search Point of View');}}); 	
});


// ACCORDION - old
//$(document).ready(function () {
//  $('LI.drawer UL').hide(); // hide all ULs inside LI.drawer except the first one
//  $('H5.drawer-handle').click(function () {
    // hide all the drawer contents
//    $('LI.drawer UL:visible').slideUp().prev().removeClass('open');

    // show the associated drawer content to 'this' (this is the current H2 element)
    // since the drawer content is the next element after the clicked H2, we find
    // it and show it using this:
//    $(this).addClass('open').next().slideDown();
//  });
//});


//$(function () {
 // $('UL.drawers').accordion({
    // the drawer handle
  //  header: 'H5.drawer-handle',
    
    // our selected class
   // selectedClass: 'open',
    
  //  event: 'mousedown'
 // });
//});


// EXTERNAL LINK
window.onload = function() {
  el = document.getElementsByTagName("a");
  for (var i=0; i<el.length; i++){
    if (el[i].rel=="external") {
      el[i].onclick = function () {
        return !window.open(this.href);
      }
    }
  }
}

// ACCORDION
$(document).ready(function() {
	$("#accordion").accordion({
		active: false,
		collapsible: true,
		autoheight: false
	});
});	

// LOAD RANDOM DIV
NumberOfDivsToRandomDisplay = 7;

var CookieName = 'DivRamdomValueCookie';
$(document).ready(function DisplayRandomDiv() {
var r = Math.ceil(Math.random() * NumberOfDivsToRandomDisplay);
if(NumberOfDivsToRandomDisplay > 1) {
   var ck = 0;
   var cookiebegin = document.cookie.indexOf(CookieName + "=");
   if(cookiebegin > -1) {
      cookiebegin += 1 + CookieName.length;
      cookieend = document.cookie.indexOf(";",cookiebegin);
      if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
      ck = parseInt(document.cookie.substring(cookiebegin,cookieend));
      }
   while(r == ck) { r = Math.ceil(Math.random() * NumberOfDivsToRandomDisplay); }
   document.cookie = CookieName + "=" + r;
   }
for( var i=1; i<=NumberOfDivsToRandomDisplay; i++) {
   document.getElementById("randomdiv"+i).style.display="none";
   }
document.getElementById("randomdiv"+r).style.display="block";
});
DisplayRandomDiv();




