function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	}else {
		return document[movieName]
	}
}

function latestNewsToggle(index){
  $(".latest_news_inner .first_item").each(function(){$(this).addClass("hidden");});
  $(".latest_news_inner .first_item."+index).removeClass("hidden");
  $(".latest_news_inner .item").each(function(){
      $(this).children("a").children(".strip_overlay").detach();
  });
  $(".latest_news_inner .item."+index+" a").prepend("<div class='strip_overlay'></div>");
}

function reset_field(){
  $(".input-reset").focus(function() {if(this.value == this.title){this.value="";}});
  $(".input-reset").blur(function() {if(this.value==""){this.value = this.title;}});
}

$(function(){
  /* invisible nav on homepage */
  $('#nav-invisible ul li').each(function(index) {
    $(this).children('a').hover(function () {
      $('#'+$(this).parent().attr("id").replace("_inv", "")).children('a').toggleClass($('#'+$(this).parent().attr("id").replace("_inv", "")).children('a').parent().attr("id")+'_hover');
    }, 
      function () {
      $('#'+$(this).parent().attr("id").replace("_inv", "")).children('a').toggleClass($('#'+$(this).parent().attr("id").replace("_inv", "")).children('a').parent().attr("id")+'_hover');
    })
  });

  /* checkbox */
  $(".checkbox_wrap").click(function(){
    if($(this).children('input').attr("checked")){
      $(this).children("label").removeClass("LabelSelected");
      $(this).children('input').removeAttr("checked")
    }else{
      $(this).children("label").addClass("LabelSelected");
      $(this).children('input').attr("checked","checked")
      if($(this).children("label").hasClass("checkbox_error")) $(this).children("label").removeClass("checkbox_error");
    }
  });

  $(".checkbox").change(function(){
    if($(this).is(":checked")){
      $(this).next("label").removeClass("checkbox_error");
      $(this).next("label").addClass("LabelSelected");
    }else{
      $(this).next("label").removeClass("LabelSelected");
    }
  });

  $(".input-reset").focus(function() {if(this.value == this.title){this.value="";}});
  $(".input-reset").blur(function() {if(this.value==""){this.value = this.title;}});

  $(".clear_search").click(function(){
    $(".input_wrap input.text").val($(".input_wrap input.text").attr("title"));
  });
  
  $("#nav-invisible").css("display","block");
  $("#carousel1_wrap").css("display","block");


  //parallax
  if(!window.location.href.match(/parallax/) || $('body').hasClass('iphone')) {
		document.body.style.backgroundAttachment = "scroll";
		document.getElementById('wrapper').style.backgroundAttachment = "scroll";
	} else {
    $('body, #wrapper').css({backgroundPosition: "(50% 0)"});
    var parallax_body = document.body.style;
    var parallax_wrapper = document.getElementById('wrapper').style;
    var parallax_scroll;

    if (window.pageYOffset == undefined) {
      parallax_scroll = function () {
        currentScrollTop = document.documentElement.scrollTop;
        
        parallax_body.backgroundPosition    = "50% " + (-currentScrollTop /  5)+ "px";
        parallax_wrapper.backgroundPosition = "50% " + (-currentScrollTop / .3)+ "px";
      };
    } else { 
      parallax_scroll = function () {
        currentScrollTop = pageYOffset;
        
        parallax_body.backgroundPosition    = "50% " + (-currentScrollTop /  5)+ "px";
        parallax_wrapper.backgroundPosition = "50% " + (-currentScrollTop / .3)+ "px";
      };
    }
    $(window).scroll(parallax_scroll);
  }

  if ($('#twitter_update_list').length > 0) {
    setTimeout(function(){
      $.getScript('http://twitter.com/statuses/user_timeline/funcom_tsw.json?count=1&callback=twitterCallback2');
    }, 1000);
  }
  if ($('#facebook_container').length > 0) {
    setTimeout(function(){
      $('#facebook_container').append('<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fthesecretworld&amp;width=250&amp;colorscheme=light&amp;show_faces=true&amp;stream=false&amp;header=false&amp;height=200" scrolling="no" frameborder="0" style="background: transparent; margin:-79px 0px 0px -10px;border:none; overflow:hidden; width:250px; height:200px;" allowTransparency="true"></iframe>');
    }, 1000);
  }


  if($.browser.msie){Printfix();}
  if($.browser.mozilla && navigator.appVersion.indexOf("Mac")!=-1){$('.social_media_share').css('letter-spacing','-1px');}
});
 
 
var roundedboxes;
var run_animation = false;
 
function Printfix(){
  window.onbeforeprint = removeRoundedboxes;
  window.onafterprint = addRoundedboxes;
}
 
function removeRoundedboxes(){
  roundedboxes1 = $("body, h1, h2, h3, h4, h5, div, p, a, span, ul, li, .media_menu ul li a, .filter_news_items a, .breadcrumb > div > a, #ft, .page_home .latest_news, .more_news, .latest_media, .email_updates, .social_media, .page_society  .box_hub, .jcarousel-skin-tango .jcarousel-container, .box_inner_page, .search_news, .latest_news_block, .see_also_block, .box_hub, .box_main_content, .box_real_world_locations, .see_also_block1, .box_all_caracters, .latest_threads_block, .funcom_posts_block, .page_media #container_top, .box_all_fansites, .box_all_fansites");
  $(roundedboxes1).css("behavior","none");
}
    
function addRoundedboxes(){
  roundedboxes2 = $(".media_menu ul li a, .filter_news_items a, .breadcrumb > div > a, #ft, .page_home .latest_news, .more_news, .latest_media, .email_updates, .social_media, .page_society  .box_hub, .jcarousel-skin-tango .jcarousel-container, .box_inner_page, .search_news, .latest_news_block, .see_also_block, .box_hub, .box_main_content, .box_real_world_locations, .see_also_block1, .box_all_caracters, .latest_threads_block, .funcom_posts_block, .page_media #container_top, .box_all_fansites, .box_all_fansites");
  $(roundedboxes2).css("behavior","url(http://funcomportal.slavoie.huewebstudio.com/css/PIE.htc)");
}

