
loc = String(window.location);
if(loc.indexOf('#') == -1 )
{
        ponth=loc.indexOf('.');
        hossz=loc.length;
        van=hossz;
        for (c=ponth;c<hossz;c++)
        {
                if (loc.substr(c,1)=='/')van=c+1;
        }
        linkh='http://dominohaz.eu/#'+loc.substr(van);

  window.location = linkh;
}

/*
if(loc.indexOf('#') == -1 && loc.length > 31)
{
  window.location = 'http://dominohaz.ysolutions.hu/#' + loc.substr(31);
} */

var lang = '';
var lastmenu = '';
var lastsubmenu = '';
var selection = new Array;
var welcome = false;
var bgfiles = new Array;
bgfiles = [
						'img/bg12.jpg',
                        'img/bg9.jpg',
                        'img/bg1.jpg',
                        'img/bg2.jpg',
                        'img/bg3.jpg',
                        'img/bg4.jpg',
                        'img/bg5.jpg',
                        'img/bg6.jpg',  
                        'img/bg7.jpg',         
                        'img/bg8.jpg',           
                        'img/bg10.jpg',
                        'img/bg11.jpg',           
                        'img/bg13.jpg',
                        'img/bg14.jpg',
                        'img/bg15.jpg',
                        'img/bg16.jpg',
                        'img/bg17.jpg'
           ];
 
function convertLinks()
{
  $("body").find("a.nav").each(function(i)
  {
    if($(this).attr("href") != undefined)
    {
      if($.browser.msie)
        $(this).attr("href", str_replace('dominohaz/','',$(this).attr("href")));
      if($(this).attr("href").substr(0,7) == "http://")
        $(this).attr("href", $(this).attr("href").substr(strpos($(this).attr("href"),"/",8)+1));
      if($(this).attr("href").substr(0,1) != "#")
      {
        $(this).attr("href", "#" + $(this).attr("href"));
        $(this).attr("onclick","_gaq.push(['_trackPageview', '" + $(this).attr("href") + "']);");
      }
    }
  });
}

function deHash(hash)
{
  return hash.substr(1);
}

function loadContent(url, callback)
{
  if(typeof(callback) == 'function')
    $("#content_inner").load("service.php?p="+url.substr(1), function() { convertLinks(); callback(); });
  else
    $("#content_inner").load("service.php?p="+url.substr(1), function() { convertLinks(); });
}

function loadMenu(selection)
{
  $("#menu_inner").load('service.php?m=' + selection[0], function() { convertLinks(); });
}

function loadLang(hash)
{
  $("#langchooser").load('service.php?l=' + selection[0], function() { convertLinks(); } );
}


function doMenu(hash)
{
  $("#menu").animate({top: "440px"},500);
}


function parseHash(hash)
{
  if(hash == '')
    return false;
  else
    return hash.substr(1).split('/');
}

function hideContent(callback)
{
  if(callback != undefined)
    $("#content").fadeOut(500, function() { callback(); } );
  else
    $("#content").fadeOut(500);
}

function doContent(hash)
{
  if($("#content").css("display") == "none")
  {
    loadContent(hash, $("#content").fadeIn(300, function() { $(".fan").fancybox(); } ));
  }
  else
  {
    $("#content").fadeOut(200, function() { loadContent(hash, function() { $("#content").fadeIn(300); $(".fan").fancybox(); }); });
  }
}

function doPager(hash)
{
  var pos = (selection[3] - 1) * - 460;
  $("#content_" + selection[2] + " .pages").animate({
    left: pos+"px"},500);
  //$("#p_" + selection[2] + "_page_nav .pager_a div").removeClass("nav_page_selected");
  //$("#p_" + selection[2] + "_" + selection[3] + " div").addClass("nav_page_selected");
  var pagenumvar = "p_" + str_replace('-','',selection[2]) + "_pages";
  if(window[pagenumvar] == selection[3])
  {
    $("#p_" + selection[2] + "_right").removeAttr("href");
    $("#p_" + selection[2] + "_right div").addClass('nav_disabled');
  }
  else
  {
    $("#p_" + selection[2] + "_right").attr("href","#"+selection[0]+"/"+selection[1]+"/"+selection[2]+"/"+(intval(selection[3])+1));
    $("#p_" + selection[2] + "_right div").removeClass('nav_disabled');
  }
  if(selection[3] == 1)
  {
    $("#p_" + selection[2] + "_left").removeAttr("href");
    $("#p_" + selection[2] + "_left div").addClass('nav_disabled');
  }
  else
  {
    $("#p_" + selection[2] + "_left").attr("href","#"+selection[0]+"/"+selection[1]+"/"+selection[2]+"/"+(intval(selection[3])-1));
    $("#p_" + selection[2] + "_left div").removeClass('nav_disabled');
  }
}

function doSubMenu(hash)
{
  hideContent();
  /*if($("#submenu").css("left") == "126px")
  {
    $("#submenu").animate({left: "-140px"},300,function(){
      $("#submenu_inner").load("service.php?s=" + deHash(hash), function() {
        convertLinks();
        $("#submenu").animate({left: "126px"},600)
      })
    });
  }
  else
  {
    $("#submenu_inner").load("service.php?s=" + deHash(hash), function() {
      convertLinks();
      $("#submenu").animate({left: "126px"},600)
    });
  }*/
  if($("#submenu").css("display") == "block")
  {
    $("#submenu_inner").fadeOut(300,function(){
      $("#submenu_inner").load("service.php?s=" + deHash(hash), function() {
        convertLinks();
        $("#submenu_inner").fadeIn(600)
      })
    });
  }
  else
  {
    $("#submenu").fadeIn(600);
    $("#submenu_inner").load("service.php?s=" + deHash(hash), function() {
      convertLinks();
      $("#submenu_inner").fadeIn(600)
    });
  }
}

function bindFunc()
{
  selection = parseHash(location.hash);

  if(hashLang())
  {
    loadLang();
    menuHider();
    loadMenu(selection);
    if(welcome)
      setTimeout(function() { doMenu(); },1000);
    else
      doMenu();
  }
  if(welcome)
    byeWelcome();

  if(hashPager())
  {
    doPager(location.hash);
  }
  if(hashSubMenu())
  {
    doSubMenu(location.hash);
  }
  if(hashContent())
  {
    doContent(location.hash);
  }
  if(hashAutoLoad())
  {
    doContent(location.hash);
  }
  if(hashBackMain())
  {
    animateHider();
  }
  if(hashHideSubmenu())
  {
    submenuHider();
  }
  convertLinks();
  setCurrent();
}

function readyFunc()
{
  selection = parseHash(location.hash);
  loadLang();
  convertLinks();

//  if(location.hash == '')

  if((location.hash == '')||(location.hash == '#'))
    welcome = true;
  else
  {
    byeWelcome();
    setTimeout(function() { bindFunc(); },1000);
  }

  $(window).bind('hashchange', function()
  {
    bindFunc();
  });
}


function byeWelcome()
{
  if($('#welcome_screen').css("display") == 'none')
    return;
  $('#welcome_screen').fadeOut(1000);
  setTimeout(function() { $('#main_screen').fadeIn(1000); },1000);
  welcome = false;
  bgChanger();
}

function menuHider()
{
  $("#menu").css("top","610px");
  //$("#submenu").css("left","-140px");
  $("#submenu").css("display","none");
  $("#content").css("display","none");
}

function animateHider()
{
  //$("#submenu").animate( { left: "-140px" });
  $("#content").fadeOut(500);
  $("#submenu").fadeOut(500);
}

function submenuHider()
{
  $("#submenu").fadeOut(500);
}

function smallCorner()
{
  $(".smlcorner").corner("4px");
}

function setCurrent()
{
  lang = selection[0];
  lastmenu = selection[1];
  lastsubmenu = selection[2];
}

function hashBackMain()
{
  if(lastmenu != undefined && selection[1] == undefined)
    return true;
}


function hashPager()
{
  if(lang == selection[0] && lastmenu == selection[1] && (lastsubmenu == selection[2] || selection[2] == ''))
    return true;
}

function hashContent()
{
  if(selection[2] != lastsubmenu && selection[2] != undefined && selection[2] != '')
    return true;
  else
    return false;
}

function hashAutoLoad()
{
  if(selection[1] == lastmenu && selection[3] != undefined)
    return false;
  if(selection[1] == 'kontakt'
    || selection[1] == 'galeria'
    || selection[1] == 'contact'
    || selection[1] == 'gallery')
    return true;
}

function hashHideSubmenu()
{
  if(selection[1] == 'gallery'
    || selection[1] == 'galeria')
  return true;
}

function hashLang()
{
  if(selection[0] != lang)
    return true;
}


function hashSubMenu()
{ 
  if(
    selection[1] != lastmenu
    && selection[1] != ''
    && selection[1] != undefined)
      return true;
}

$(document).ready(function() {
  DD_roundies.addRule('.corner', '12px', true);
  setTimeout(function() { $.preLoadImages(bgfiles); },500);
  menuHider();
  mainReady();
  readyFunc();
});


function mainReady()
{
  //if(!$.browser.msie || intval($.browser.version) > 8)
  //$(".corner").corner("12px");
  
  $(function ()
    {
    $.ajaxSetup
        ({
        xhr: function()
            {
            if ($.browser.msie)
                {
                return new ActiveXObject("Microsoft.XMLHTTP");
                }
            else
                {
                return new XMLHttpRequest();
                }
            }
        })
    });
}

(function($) {
  var cache = [];
  $.preLoadImages = function() {
    arguments = arguments[0];
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)


/***** UTIL *****/

function dump(obj)
{
    var out = '';
    for (var i in obj) {
        out += i + ": " + obj[i] + "\n";
    }
    alert(out);
    // or, if you wanted to avoid alerts...
    var pre = document.createElement('pre');
    pre.innerHTML = out;
    document.body.appendChild(pre)
}


function strpos(haystack, needle, offset)
{
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}


function intval (mixed_var, base) {
    // Get the integer value of a variable using the optional base for the conversion  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/intval
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Matteo
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4
    // *     example 3: intval(42, 8);
    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9
    // *     example 5: intval('1e', 16);
    // *     returns 5: 30
    var tmp;
 
    var type = typeof( mixed_var );
 
    if (type === 'boolean') {
        return (mixed_var) ? 1 : 0;
    } else if (type === 'string') {
        tmp = parseInt(mixed_var, base || 10);
        return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;
    } else if (type === 'number' && isFinite(mixed_var) ) {
        return Math.floor(mixed_var);
    } else {
        return 0;
    }
}

function str_replace (search, replace, subject, count) {
    // Replaces all occurrences of search in haystack with replace  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/str_replace    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
     for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}        }
    }
    return sa ? s : s[0];
}


/***** DOMINO *****/

function bgChanger()
{
  $(".bg1").css('background-image','url(' + bgfiles[0] + ')');
  var i = 1;
  var tochange = $(".bg1");
  setInterval(function()
  {  
    if($(".bg1").css('display') == 'none')
      tochange = $(".bg1");
    else
      tochange = $(".bg2");
    tochange.css('background-image','url(' + bgfiles[i] + ')');    
    if(i == bgfiles.length - 1)
      i = 0;
    else
      i ++;
    if($(".bg1").css('display') == 'none')
    {
      $(".bg1").css("z-index",1);
      $(".bg1").fadeIn(4000,function(){
        $(".bg2").css("display","none");
      })
    }
    else
    {
      $(".bg1").css("z-index",0);
      $(".bg2").fadeIn(4000,function(){
        $(".bg1").css("display","none");
      })
    }
  },12000)
}


