// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


function hover_nav(e, img) {
  $(e).src="/assets/images/layouts/navigation/"+img;
}

// ################
// #### NEWS TEASER
// ################
function reset_news_teaser() {
  new Effect.Fade('news_teaser',{duration: 1.0, afterFinish:function(){rotate_news();}});
}

function rotate_news() {

  var n = $('news_id').value;
  var params = "news_id="+n;
  var go_url = "/news_and_events/get_next.cfm";

  new Ajax.Request(go_url, {
        method:'post', 
        parameters: params, 
        onSuccess: function(obj){show_news(obj, 'success');}, 
        onFailure:function(obj){show_news(obj, 'fail');}
      });
}

function show_news(obj, s) {
   if (s == 'success') {
    $('news_teaser').innerHTML = obj.responseText;
    Effect.SlideDown('news_teaser', {duration: 1.0});
   } else {
      //alert('error');
   }
}

// ################
// #### FEATURED OWNERS
// ################
function reset_featured_owners() {
  new Effect.Fade('featured_owners_container',{duration: 1.0, afterFinish:function(){rotate_featured_owners();}});
}


function rotate_featured_owners() {
  var params = "owners_ids=1,3,5,7";
  var go_url = "/owners_area/ajax/featured.cfm";

  new Ajax.Request(go_url, {
        method:'post', 
        parameters: params, 
        onSuccess: function(obj){show_featured_owners(obj, 'success');}, 
        onFailure:function(obj){show_featured_owners(obj, 'fail');}
      });
}

function show_featured_owners(obj, s) {
   if (s == 'success') {
    $('featured_owners_container').innerHTML = obj.responseText;
    new Effect.Appear('featured_owners_container', {duration: 1.0});
   } else {
      //alert('error');
   }
}

// ################
// #### OWNERS STORIES
// ################

function rotate_owner_stories() {
  var params = "story_ids=1,3,5,7";
  var go_url = "/owners_area/ajax/stories.cfm";

  new Effect.SlideUp('owners_stories',{duration: .5, afterFinish:function(){
    new Ajax.Request(go_url, {
          method:'post', 
          parameters: params, 
          onSuccess: function(obj){show_owner_stories(obj, 'success');}, 
          onFailure:function(obj){show_owner_stories(obj, 'fail');}
        });
  }});
}

function show_owner_stories(obj, s) {
   if (s == 'success') {
    $('owners_stories').innerHTML = obj.responseText;
    new Effect.SlideDown('owners_stories', {duration: .5});
   } else {
      //alert('error');
   }
}

// ################
// #### OWNERS GALLERY
// ################

function rotate_owner_gallery() {
  var params = "story_ids=1,3,5,7";
  var go_url = "/owners_area/ajax/gallery.cfm";

  new Effect.SlideUp('owner_gallery_photos',{duration: .5, afterFinish:function(){
    new Ajax.Request(go_url, {
          method:'post', 
          parameters: params, 
          onSuccess: function(obj){show_owner_gallery(obj, 'success');}, 
          onFailure:function(obj){show_owner_gallery(obj, 'fail');}
        });
  }});
}

function show_owner_gallery(obj, s) {
   if (s == 'success') {
    $('owner_gallery_photos').innerHTML = obj.responseText;
    new Effect.SlideDown('owner_gallery_photos', {duration: .5});
   } else {
      //alert('error');
   }
}

//MISC JS FUNCTIONS
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}