// JavaScript Document

var $jq = jQuery.noConflict();

$jq(document).ready(function(){
				 
						 

	// Thumb Hover				   
	$jq('.img_thumb').each(function () {
		$jq('<div class="shad_hover" />').css('opacity', 0).prependTo(this);
	}).hover(function () { 
		$jq('.shad_hover', this).stop().animate({ opacity : 0.35 }, 500 );
	}, function () {
		$jq('.shad_hover', this).stop().animate({ opacity : 0 }, 500 );
	});
		
	// Position Contact Container At Top
	$jq("#page_container").css({ paddingTop: "27px" });
	$jq("#contact_frame").css({ display: "block" });
	$jq("#contact_container").css({ position: "absolute", top: "-140px" });	
	$jq("#contact_center").css({ background: "white" });
	$jq("#Message").css({ background: "#ecf1f4" });
	$jq("#Name").css({ background: "#ecf1f4" });
	$jq("#Email").css({ background: "#ecf1f4" });
	$jq("#message label").css({ display: "none" });
	$jq("#Message").height(72);
	$jq("#form li label").css({ display: "none" });
			
	// Show X Close Button
	$jq(".close").after('<a class="closeContact" href="#">[X]</a>');
	
	// Contact Slide Toggle
	$jq(".toggleContact").toggle(function(){
		$jq("#contact_container").animate({ top: "0px" }, 500 );
		$jq("#page_container").animate({ paddingTop: "167px" }, 500 );
		$jq(".toggleContact").addClass("selected");
	},function(){
		$jq("#contact_container").animate({ top: "-140px" }, 500 );
		$jq("#page_container").animate({ paddingTop: "27px" }, 500 );
		$jq(".toggleContact").removeClass("selected");
	});
	
	// Close Contact Slide
	$jq(".closeContact").click(function(){
		$jq(".toggleContact").trigger('click');
	});
	
	

	
	// Form CLick Clear
	
	// set all class .text default value according to alt attribute
		$jq(".text").each(function(){
			$jq(this).val($jq(this).attr("id"));
			$jq(this).css({ color: "Grey" });
		});
		 
		// clear input.text on focus, if still in default
		$jq(".text").focus(function() {
		 
			if($jq(this).val()==$jq(this).attr("id")) {
				$jq(this).val("");
			}
			$jq(this).css({ color: "Black" });
		});
		 
		// if field is empty afterward, add text again
		$jq(".text").blur(function() {
			if($jq(this).val()=="") {
				$jq(this).val($jq(this).attr("id"));
				$jq(this).css({ color: "Grey" });
			}
			
		});
		
		
	
								
//----------------------------------	

var $jqpanels = $jq('#left_column .scrollContainer > div');
var $jqcontainer = $jq('#left_column .scrollContainer');

// if false, we'll float all the panels left and fix the width 
// of the container
var horizontal = true;

// float the panels left if we're going horizontal
if (horizontal) {
  $jqpanels.css({
    'float' : 'left',
    'position' : 'relative' // IE fix to ensure overflow is hidden
  });
  
  // calculate a new width for the container (so it holds all panels)
  //$jqcontainer.css('width', $jqpanels[0].offsetWidth * $jqpanels.length);
}

// collect the scroll object, at the same time apply the hidden overflow
// to remove the default scrollbars that will appear
var $jqscroll = $jq('#left_column .scroll').css('overflow', 'hidden');

// apply our left + right buttons
$jqscroll
//  .before('<img class="scrollButtons left" src="images/scroll_left.png" />')
//  .after('<img class="scrollButtons right" src="images/scroll_right.png" />');

// set first thumbnail to already selected
$jq("#image_main_thumb_0").parent().addClass('selected');

// handle nav selection
function selectNav() {
  $jq(this)
    .parents('div.navigation')
      .find('a')
        .removeClass('selected')
      .end()
    .end()
    .addClass('selected');
}

$jq('#left_column .navigation').find('a').click(selectNav);

// go find the navigation link that has this target and select the nav
function trigger(data) {
  var el = $jq('#left_column .navigation').find('a[href$jq="' + data.id + '"]').get(0);
  selectNav.call(el);
}

if (window.location.hash) {
  trigger({ id : window.location.hash.substr(1) });
} else {
  $jq('ul.navigation a:first').click();
}

// offset is used to move to *exactly* the right place, since I'm using
// padding on my example, I need to subtract the amount of padding to
// the offset.  Try removing this to get a good idea of the effect
var offset = parseInt((horizontal ? 
  $jqcontainer.css('paddingTop') : 
  $jqcontainer.css('paddingLeft')) 
  || 0) * -1;


var scrollOptions = {
  target: $jqscroll, // the element that has the overflow
  
  // can be a selector which will be relative to the target
  items: $jqpanels,
  
  navigation: '.navigation a',
  
  // selectors are NOT relative to document, i.e. make sure they're unique
  prev: 'img.left', 
  next: 'img.right',
  
  // allow the scroll effect to run both directions
  axis: 'xy',
  
  onAfter: trigger, // our final callback
  
  offset: offset,
  
  // duration of the sliding effect
  duration: 500,
  
  // easing - can be used with the easing plugin: 
  // http://gsgd.co.uk/sandbox/jquery/easing/
  easing: 'swing'
};

});
     

	// External Links
function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 
window.onload = externalLinks;
