
/* jquery scope */
$(document).ready(function(){


  /* print */
  $('.print').click(function(){
    self.print();
    return false;
  });
  
  
  
  /* boomark */
  $('#bookmarkme').jFav();
  
  /* sitemap */
  $('#doSitemap').click(function(){
    openSitemap();
    return false;
  });
  
  
  /* Kinder selector */
  $('select#doFormChildSelector').change(function(){
  
    test = $(this).val();
    if (test) {
      document.childSelector.submit();
    }
  });
  
  
  
  /* produkte image preview */
  imagePreview();
  
  
  /* shop target open window */
  /*
   $('a[title=Shop]').click(function(){
   xlink = $(this).attr("href");
   doOpenBlankWindow(xlink, 'shopName');
   return false;
   });
   */
  /* shop target open window */
  $('.filelinks a').click(function(){
    xlink = $(this).attr("href");
    doOpenBlankWindow(xlink, 'fileLinks');
    return false;
  });
  
  
  
  
  /* video links aus contet */
  $('a').click(function(){
    xtitle = $(this).attr("title");
    
    if (xtitle == 'Videos' ||
    xtitle == 'MediaCenter') {
      openMediacenter('/index.php?id=702');
      return false;
    }
    
  });
  
  
  
  /* carousel Film teaser */
  $('#mycarousel a').click(function(){
    xhref = $(this).attr("href");
    
    testFilmName = /film=(.*).flv/;
    tmp = xhref.match(testFilmName);
    
    if (tmp) {
      if (tmp[1]) {
        openMediacenter('/index.php?id=702&film=' + tmp[1] + '.flv');
        return false;
      }
    }
    
  });
  
  
  
  
  /* carousel popup teaser */
  $('#mycarousel a').click(function(){
    xhref = $(this).attr("href");
    
    
    testFilmName = /(.*)#popup860,0/;
    tmp = xhref.match(testFilmName);
    
    if (tmp) {
      if (tmp[1]) {
        popWinMedia = window.open(xhref, 'popup', "width=860,height=630,fullscreen=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,titlebar=yes");
        popWinMedia.focus();
        return false;
      }
    }
    
    
    testFilmName = /(.*)#popup,0/;
    tmp = xhref.match(testFilmName);
    
    if (tmp) {
      if (tmp[1]) {
        //popWinMedia = window.open(xhref, 'popup', "width=700,height=700,fullscreen=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,titlebar=yes");
        popWinMedia = window.open(xhref, 'popup', "width=860,height=630,fullscreen=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,titlebar=yes");
        popWinMedia.focus();
        return false;
      }
    }
    
    
    
  });
  
  
  
  /* AGB popup */
  $('a.agbpopup').click(function(){
    openAGBPopup('/index.php?id=57&type=98');
    return false;
  });
  
  /* pageflip */
  $("#pageflip").hover(function(){ //On hover...
    $("#pageflip img , .msg_block").stop().animate({ //Animate and expand the image and the msg_block (Width + height)
      width: '307px',
      height: '319px'
    }, 500);
  }, function(){
    $("#pageflip img").stop() //On hover out, go back to original size 50x52
.animate({
      width: '50px',
      height: '52px'
    }, 220);
    $(".msg_block").stop() //On hover out, go back to original size 50x50
.animate({
      width: '50px',
      height: '50px'
    }, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
  });
  
  
});

function openAGBPopup(url){
  popWinMedia = window.open(url, 'agbPopup', "width=950,height=600,fullscreen=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,titlebar=yes");
  popWinMedia.focus();
  
  return false;
}

function openMediacenter(url){
  popWinMedia = window.open(url, 'mediaCenter', "width=960,height=480,fullscreen=no,location=no,menubar=no,status=no,scrollbars=no,resizable=no,titlebar=yes");
  popWinMedia.focus();
  return false;
}



function doOpenBlankWindow(url, name){
  popWin = window.open(url, name, "fullscreen=yes,location=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes,titlebar=yes");
  popWin.focus();
}



/* misc functions */
function openSitemap(){
  Navigation = window.open("index.php?id=836&type=98", "Navigation", "height=600,width=350,scrollbars=yes");
  Navigation.focus();
  return false;
}

function openBigImage(){
  //Navigation.focus();
  
  //$(this).add("span");
  return false;
}




/* ********************
 IMAGE preview
 ******************** */
this.imagePreview = function(){
  /* CONFIG */
  
  yOffset = 260;
  xOffset = 20;
  
  // these 2 variable determine popup's distance from the cursor
  // you might want to adjust to get the right result
  
  /* END CONFIG */
  $("a.preview").hover(function(e){
    this.t = this.title;
    this.title = "";
    //var c = (this.t != "") ? "<br/>" + this.t : "";
    //$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
    $("body").append("<p id='preview'><img src='" + this.href + "' alt='Image preview' /></p>");
    $("#preview").css("top", (e.pageY - yOffset) + "px").css("left", (e.pageX + xOffset) + "px").fadeIn("fast");
  }, function(){
    this.title = this.t;
    $("#preview").remove();
  });
  
  $("a.preview").mousemove(function(e){
    $("#preview").css("top", (e.pageY - yOffset) + "px").css("left", (e.pageX + xOffset) + "px");
  });
  
  $("a.preview").click(function(e){
    return false;
  });
  
  
  
};



function include(file){
  var script = document.createElement('script');
  var type = document.createAttribute('type');
  type.nodeValue = 'text/javascript';
  script.setAttributeNode(type);
  var source = document.createAttribute('src');
  source.nodeValue = file;
  script.setAttributeNode(source);
  var head = document.getElementsByTagName('head')[0];
  head.appendChild(script);
}


function ReadCookie(cookieName){
  var theCookie = "" + document.cookie;
  var ind = theCookie.indexOf(cookieName);
  if (ind == -1 || cookieName == "") 
    return "";
  var ind1 = theCookie.indexOf(';', ind);
  if (ind1 == -1) 
    ind1 = theCookie.length;
  return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
}

function SetCookie(cookieName, cookieValue, nDays){
  var today = new Date();
  var expire = new Date();
  if (nDays == null || nDays == 0) 
    nDays = 1;
  expire.setTime(today.getTime() + 3600000 * 24 * nDays);
  document.cookie = cookieName + "=" + escape(cookieValue) +
  ";expires=" +
  expire.toGMTString();
}






