/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);



$(document).ready(function(){
  
  /* MAIN MENU */
  
  $('.wre-main-menu-item').each(function(){
    if($(this).text().toLowerCase() == "work"){
		$(this).next().find('.wrapper').html('');
		$('#wre-menu-work-content').appendTo($(this).next().find('.wrapper'));
    }
    
    if(!$(this).next().find('.wrapper a').length){
    	$(this).next().remove();
    }
  });
  
  $('.wre-main-menu-level2 .wrapper').each(function(){
		$(this).find('a:last').css({border:'none'});
  });
  
  /* WORK SECTION REPLACEMENT */

  $('.wre-main-menu > div').hoverIntent({
    timeout:250,
    interval:50,
    over:function(){
      $(this).find('.wre-main-menu-level2').fadeIn(100);
    },
    out:function(){
      $(this).find('.wre-main-menu-level2').fadeOut(100);
    }
  });
  
  
  /* SIDE MENU */
  var _original = $('.wre-side-menu-wrapper').find('a#1').text() + " //";
  $('.wre-side-menu-wrapper').find('a#1').text(_original);
});



$(document).ready(function(){
  
  // global varaiables
  var $_total = $('#wre-work-slideshow .item').length;
  var $navigation = $('#wre-work-slideshow-pagination ul');
  var $slideshow_width = $('#wre-work-slideshow').width();
  var $_total_width = $_total * $slideshow_width;
  var $_first = $('#wre-work-slideshow .item:first');
  var $npos = 0;
  
  // data
  $('#wre-work-slideshow .item').each(function(index){
    var _description = $(this).find('.description').text();
    var _img = $(this).find('.image').attr('src');
    var _id = index;
    
    $(this).data('id',index);
    $(this).data('description',_description);
    $(this).data('image',_img);
    
    $(this).css({background:'url("' + _img + '") no-repeat 50% 50%'});
    
    if(index < 9){
      $('<li><a href="#">0' + (index + 1) + '</a></li>').data('id',index).appendTo($navigation);
    }else{
      $('<li><a href="#">' + (index + 1) + '</a></li>').data('id',index).appendTo($navigation);
    }
    
    $('<li class="divider">/</li>').appendTo($navigation);
    
    $(this).find('.image').remove();
    //$(this).find('.description').remove();
  });
  
  // init
  $navigation.find('li.divider:last').remove();
  $('#gallery-container').css('width',$_total_width);
  update($_first);
  
  
  
  // pagination
  $('#wre-work-slideshow-pagination ul a').click(function(e){
    e.preventDefault();
    var _id = $(this).parents('li').data('id');
    
    $npos = _id;
    
    update($('#wre-work-slideshow .item').eq($npos));
  });
  
  $('#wre-work-slideshow-pagination .pagination-left').click(function(e){
    e.preventDefault();
    $npos--;
    if($npos < 0) $npos = 0;
    update($('#wre-work-slideshow .item').eq($npos));
  });
  
  $('#wre-work-slideshow-pagination .pagination-right').click(function(e){
    e.preventDefault();
    $npos++;
    if($npos > $_total-1) $npos = $_total-1;
    update($('#wre-work-slideshow .item').eq($npos));
  });
  
  
  // functions
  function update(object){
    $('#wre-work-slideshow-pagination ul a').removeClass('active');
    $('#wre-work-slideshow-pagination ul a').eq($npos).addClass('active');
  
    $('#wre-work-slideshow-description').html(object.find('.description').html());
    $('#gallery-container').animate({left:$npos * -$slideshow_width}, 300);
  }
});



/*
$(document).ready(function(){

  $('.wre-side-menu-wrapper a').live("click",function(e){
    
    e.preventDefault();
        
    $('.wre-side-menu-wrapper a').each(function(i){
      $(this).data('count',i);
    });
    
    var _anchor = $(this);
    var _link = $(this).attr('href');
    var _id = $(this).attr('id');
    var _count = $(this).data('count');
    
    $.ajax({ 
      url: _link, 
      context: document.body,
      type:"get", 
      success: function(data){
        
        var sidemenu = $(data).find('.wre-side-menu-wrapper');
        var content = $(data).find('#wre-work-slideshow');
        
        sidemenu.find('a').each(function(i){
          if( parseInt($(this).attr('id')) > parseInt(_id) ){      
            log(i);
            var pos = $('.wre-side-menu-wrapper a').eq(count+i);
            $(this).insertAfter(pos);
          }
        });
    }});
    
  });
  
});

function log(msg) {
    if (window.console) {
        console.log(msg);
    }
}
*/

/* reverseOrder : jQuery order reverser plugin
 * Written by Corey H Maass for Arc90
 * (c) Arc90, Inc.
 * 
 * Licensed under:Creative Commons Attribution-Share Alike 3.0 http://creativecommons.org/licenses/by-sa/3.0/us/
 */

(function($){$.fn.reverseOrder=function(){return this.each(function(){$(this).prependTo($(this).parent())})}})(jQuery);



jQuery.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return jQuery.getUrlVars()[name];
  }
});

$(document).ready(function() {
    
  //Clear input value on focus
  if($(".form").length) {
    $(".form input.text").focus(function() {
        $(this).val("");
    });   
  }
  
//Close .ready()  
});


var openPopup = window.open;

function show_msg(msg) { alert(msg); }

function validateForm() {
	missing_required = 0;

	for (i = 0; i < arguments.length; i++) {
		if(arguments[i] == '') {
			missing_required = 1;
		}
	}

	if(missing_required) {
		alert("A required form field is missing.");
		return false;
	} else {
		return true;
	}
}

function expCustomLink(myURL) {
	location.href = myURL;
}

function setUrl(path) {
	document.location.href = path;
}

function expArticleLink(sectionId, articleId) {
	location.href = '/index.php?section_id=' + sectionId + '&section_copy_id=' + articleId;
}

function expPopupWindow(url, widthVal, heightVal, resizableVal, scrollbarsVal, toolbarVal, locationVal, directoriesVal, statusVal, menubarVal, copyHistoryVal) {

	var attributes = "width="  	 	 + widthVal       +
				 	 ",height=" 	 + heightVal      +
				 	 ",resizable="  + resizableVal  +
				 	 ",scrollbars="  + scrollbarsVal  +
				 	 ",toolbar=" 	 + toolbarVal 	  +
				 	 ",location=" 	 + locationVal 	  +
				 	 ",directories=" + directoriesVal +
				 	 ",status=" 	 + statusVal 	  +
				 	 ",menubar=" 	 + menubarVal 	  +
				 	 ",copyhistory=" + copyHistoryVal;

	window.open(url, 'WindowName', attributes);
}

function xprLog(msg) {
    if (window.console) console.log(msg);
}

if (document.addEventListener) {  
    document.addEventListener("DOMContentLoaded", function () { if (typeof onXprPageLoad == 'function') onXprPageLoad(); }, false);
} else if (document.attachEvent) {  
    document.attachEvent('DOMContentLoaded', function () { if (typeof onXprPageLoad == 'function') onXprPageLoad(); });
}  

