﻿/* SEO AJAX Framework */
/* Preferences */

var loader = true; // false if no Loader
var http = false;

var parts = window.location.href.split("#");


if(navigator.appName == "Microsoft Internet Explorer") 
{
    try 
    { 
        http = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    catch (e) 
    { 
        try 
        { 
            http = new ActiveXObject("Msxml2.XMLHTTP"); 
        }
        catch (e) 
        {} 
    } 
} 
else 
{
        http = new XMLHttpRequest(); 
        if (http.overrideMimeType) 
        { 
            http.overrideMimeType('text/html'); 
        } 
}


if(parts.length > 1)
{
        location.href=parts[1];
}
function debug(msg, clear) {
        var output = 
                document.getElementById("output");
        if (clear == true)
          output.innerHTML = "<p>" + msg + "</p>";
        else {
          output.innerHTML += 
                            "<p>" + msg + "</p>";
        }
}


        
//Load function to add onclick function to menuitems
window.onload = Init;
function Init(){

    
    dhtmlHistory.addListener(historyChange);
    if(document.getElementsByTagName)
    {
        //Get all element with tag <a>
        var links = document.getElementsByTagName('a');
        var menuUrl = "#";
        
        //Browse arraylist Links
        for(var i = 0; i < links.length ; i++)
        {
            //If elmenent is a menuitem
            if(links[i].className.match('MenuItem'))
            {
                  //Add function to onclick
                  links[i].onclick = function(){
                   
                  var att = this.attributes;
                  menuUrl = att.getNamedItem("href").value;
                 
                  dhtmlHistory.add(menuUrl, true);
                  window.status = att.getNamedItem("title").value;
                  document.title = att.getNamedItem("title").value;
				  contdv = att.getNamedItem("class").value;
				  
				  var cont = contdv.split("#");
				  contdiv = cont[1];
                  getHTML(menuUrl, contdiv);
                  return false;
                };
            }
        }
    }
    return true;
}
function historyChange(newLocation, historyData) {
        if(newLocation == "")
        {
            getHTML("index.html");
        }
        else
        {
            getHTML(newLocation);
        }
}

function getHTML(menuUrl, contdiv)
{
 
  //Open url given by href attribute
  http.open("GET",menuUrl, true);
  
  //If page is loaded
  http.onreadystatechange=function() {
    if(http.readyState == 3)
    {
        if(loader)
        {
        document.getElementById(contdiv).innerHTML = "<br/><br/><center><img src=\"http://blagavest.bg/images/slider/ajax_loader.gif\" title=\"Loading...\" /></center>";
        }
    }
    if(http.readyState == 4) {
        if(http.status == 200)
        {
        FadeIn( 0 );
document.getElementById(contdiv).style.display = "block";
for( var i = 0 ; i <= 100 ; i++ )
setTimeout( 'FadeIn(' + (i / 10) + ')' , 3 * i );
             div=document.createElement('div');  
             div.innerHTML = http.responseText;
             document.getElementById(contdiv).innerHTML = gethtmlDiv(div);
                         Init();
                         
                         if(contdiv == 'video' || contdiv == 'content'){
                         VideoJS.setup();
						 }
						 
						 if(contdiv == 'content'){
                         $(document).ready(function() {
    $('.slideshow').cycle({
		fx: 'shuffle' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
});
						 }

            $(function(){
			
			$("#main-photo-slider").codaSlider();
			
			$navthumb = $(".nav-thumb");
			$crosslink = $(".cross-link");
			
			$navthumb
			.click(function() {
				var $this = $(this);
				theInterval($this.parent().attr('href').slice(1) - 1);
				return false;
			});
			
		});   
        }
        else
        {
             document.getElementById(contdiv).innerHTML = "<center>... Could not open page ...</center>";
        }
    }
  }
  
  http.setRequestHeader("Content-Type", "text/html");
  http.send(null);
  return true;
}
function FadeIn(value) {
document.getElementById(contdiv).style.opacity = value / 10;
document.getElementById(contdiv).style.filter = 'alpha(opacity=' + value * 10 + ')';
}
function gethtmlDiv(dv)
{
    var html;
    var boolfound = false;
    
    for(var j=0,d;d=dv.childNodes[j];j++)
    {

         if(d.nodeName == 'DIV')
         {
           if(d.id)
           {
               if(d.id.match(contdiv))
               {
                     html = d.innerHTML;
                     boolfound = true;
               }
               else
               {
                    html = gethtmlDiv(d);
               }
            }
            else
            {
                    html = gethtmlDiv(d);
            }
        }
        else
        {
                html = gethtmlDiv(d);
        }
        
        if(html)
        {
            break;
        }
        if(boolfound)
        {
            break;
        }
    }
    return html;
}


