// SWFobject for IPS by sveinung@idium.no Feb 2010
(function f(b){var d=window.ips=window.ips||{},c=b||{loading:false},e;if(d.queue===undefined)d.queue=[];if(typeof window.swfobject!=="undefined"&&typeof window.swfobject.embedSWF!=="undefined")c.loading=false;else if(d.queue.length>0){if(c.loading===false){b=document.createElement("script");b.type="text/javascript";b.async=true;b.src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js";(document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(b); c.loading=true}e=setTimeout(function(){f(c)},50)}if(c.loading===false&&d.queue.length>0)for(b=0;b<d.queue.length;b++){var a=d.queue[b];if(!a.loaded){a.loaded="true";swfobject.embedSWF(a.url,a.element,a.width,a.height,a.version,a.expressInstall,a.flashvars,a.params,a.attributes)}}if(c.loading===false&&typeof window.jQuery!=="undefined")e=setTimeout(function(){jQuery(document).one("ajaxStart",function(){e=setTimeout(function(){f(c)},100)})},2E3)})();
jQuery(document).ready(function() {

  
/*  if($("body.frontpage2010").length) {
      var footerTopPosition = (screen.availHeight)-180;
  }
    else if(((screen.availHeight)-180)>$("body").height()) {
    var footerTopPosition = (screen.availHeight)-200;
    }
    else  footerTopPosition = $("body").height();
   var footerLeftPosition = ((screen.availWidth)/2) - (980/2);
   $(".footer").css({position:'absolute',top:footerTopPosition,left:footerLeftPosition });

 */

   // Searchform interaction
   var $searchForm = $("#searchForm"), //CACHE
       $query = $searchForm.find(".query"),
       $label = $searchForm.find("label");
   if ($query.val() !== "") {$label.hide()}
   $searchForm.submit(function(){
   if ($query.val() === "") {return false}
   });
   $query.focus(function(){$label.hide()}).blur(function(){
     if ($(this).val() === "") {$label.show()}
   });
   $searchForm.find("label").click(function(){
    $query.focus();
   }); 
   // END SEARCHFORM
/* #### CASE IMAGE GALLERY v 0.1.2 #### */

var imgCount = $(".slideImg").length;
var slidePos = 1; // init slider position

var removeCurrent = function() {
  $(".slideImg:eq("+(slidePos-1).toString()+")").fadeOut();
  $(".casegallery ul li:eq("+(slidePos-1)+")").removeClass("current").children("a").text($(".casegallery ul li:eq("+(slidePos-1)+") a").text().replace("(","").replace(")","")); /* removes class curent and replaces brackets */
}
 
var addCurrent = function() {
  $(".slideImg:eq("+(slidePos-1).toString()+")").fadeIn();
  $(".casegallery ul li:eq("+(slidePos-1)+")").addClass("current").children("a").append(")").prepend("("); // adds brackets 
}

var nextSlide = function() {
  if(slidePos<imgCount) {
  next = slidePos+1;
  slideTo(next);
  }
  else slideTo(1); // reached the end, going back to first
}

var slideTo = function(slideNumber) {
    if(slideNumber!=slidePos) { // don't slideTo when clicking on the same slide
      removeCurrent();
      slidePos = slideNumber;
      addCurrent(); 
    }
}

  $(".casegallery").bind("slide",function(){
      nextSlide(); 
  });


var slideListHtml = '<ul>';
for(x=1;x<imgCount+1;x++) {
  if (x==1) y='(1)'; else y = x; // add parenthesis to first item
  slideListHtml += '<li><a href="#'+x+'">'+y+'</a></li>\n';
}
slideListHtml += '</ul>';

$(".casegallery").append(slideListHtml);
$(".casegallery ul li:eq("+(slidePos-1)+")").addClass("current");  
$(".casegallery ul a").click(function(e) {
  autoslide=false; // disable autoslider
  e.preventDefault();
  slideTo($(this).attr("href").replace("#",""));
});
// END OF CASE IMAGE GALLERY

$(".facebook a").click(function(e) {e.preventDefault();facebook_click();});
$(".twitter a").click(function(e) {e.preventDefault();twitter_click();});
$(".linkedin a").click(function(e) {e.preventDefault();lindedin_click();});

}); // END OF CODE EXECUTED ON DOCUMENT READY

var autoslide = true;
setInterval("if(autoslide)jQuery('.casegallery').trigger('slide'); ",4000);

function facebook_click() {
 u=location.href;
 t=document.title;
 window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
 return false;
}

function twitter_click() {
 u=location.href;
 t=document.title;
 window.open('http://twitter.com/home?status='+encodeURIComponent(t)+' '+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');
 return false;
}

function lindedin_click() {
 u=location.href;
 t=document.title;
 window.open('http://www.linkedin.com/shareArticle?mini=true&url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
 return false;
}
