var wrapper,left,leftInner,right,rightInner, header, headerInner, bottom, bottomInner;
var wrapperO,leftO,rightO,headerO, bottomO;
var diffBG='body', diffBGOldVal=1;
var ft=0;
var bgtransitionTimer=5000;
var gObjID, gPostID,gObjID2,gPostID2;
var loading='<div style="width:100%;height:100%;text-align:center;padding-top:150px;"><img src="./themes/default/ajax-loader.gif"></div>';
$(document).ready(function(){
    $.ajaxSetup({
      async:true,
      url: "./",
      global: false,
      type: "POST"
    });

    $.extend({
      getUrlVars: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
          hash = hashes[i].split('=');
          vars.push(hash[0]);
          vars[hash[0]] = hash[1];
        }
        return vars;
      },
      getUrlVar: function(name){
        return $.getUrlVars()[name];
      }
    });
    
    gObjID  = $.getUrlVars()['objID'];
    gPostID = $.getUrlVars()['postID'];
    gObjID2  = $.getUrlVars()['objID2'];
    gPostID2 = $.getUrlVars()['postID2'];
    
    wrapper     = $("#wrapper");wrapperO = wrapper.css('opacity');
    left        = $(".left");leftO = left.css('opacity');
    leftInner   = $(".leftInner");
    right       = $(".right");rightO = right.css('opacity');
    rightInner  = $(".rightInner");
    header      = $(".header");headerO = header.css('opacity');
    headerInner = $(".headerInner");
    bottom      = $(".bottom");bottomO = bottom.css('opacity');
    bottomInner = $(".bottomInner");
    $("#loading").ajaxStart(function(){$(this).css('opacity',1).fadeIn(ft);}).ajaxStop(function(){$(this).fadeOut(ft);});
    
    setTimeout('startupPage();',100);
    soundManagerInit();
    if ($.browser.webkit) {
        $(".sf-menu").css('margin-top','18px');
    }


});

function formatText(index, panel) {
    return index + "";
}

function sk_StartSlider() {
    $('.anythingSlider').anythingSlider({
        easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
        autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
        delay: 3000,                    // How long between slide transitions in AutoPlay mode
        startStopped: false,            // If autoPlay is on, this can force it to start stopped
        animationTime: 600,             // How long the slide transition takes
        hashTags: true,                 // Should links change the hashtag in the URL?
        buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
                pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
                startText: "Έναρξη",                // Start text
                stopText: "Παύση",               // Stop text
                navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
    });
    
    $("#slide-jump").click(function(){
        $('.anythingSlider').anythingSlider(6);
    });
}

function sk_arrangeWindows()
{
    var dh = $(window).height();
    docwidth = $(window).width();
    docheight= $(window).height();
    //$("#accordion").css
}

function startupPage() {
    diffBG = "wrapper01";
    sk_goBgTimer();
    wrapper.fadeIn(ft, function() {
       header.fadeIn(ft, function() { 
        headerInner.fadeIn(ft,function() {
            bottom.fadeIn(ft,function() {
                bottomInner.fadeIn(ft,function() { 
                    if ( (gObjID == '') || (gObjID==undefined) ) { 
                    	//document.location="index.php?objID=-1&PostID=213";
			document.location="index.php?objID=362&PostID=0";
                    } else {
                    	sk_showLeftMenuNoAjax();
                    }
                });
            });
        });
       });
    });
}

function showVideo(youtubeID) {
    var html = "<p><object width='800' height='450'> "+
                    "<param name='movie' value='http://www.youtube.com/v/"+youtubeID+"&hl=en&fs=1'> "+
                    "<param name='type' value='application/x-shockwave-flash'> "+
                    "<param name='allowfullscreen' value='true'> "+
                    "<param name='allowscriptaccess' value='always'> "+
                    "<param name='wmode' value='opaque' /> "+
                    "<embed width='800' height='450' "+
                    "        src='http://www.youtube.com/v/"+youtubeID+"&hl=en&fs=1' "+
                    "        type='application/x-shockwave-flash' "+
                    "        allowfullscreen='true' "+
                    "        allowscriptaccess='always' "+
                    "        wmode='opaque' "+
                    "></embed> "+
                "</object></p>";

    $.fn.ceebox.popup(html,{width:800,height:450});
}

function showDiv(myDiv,options) {
    $.fn.ceebox.overlay();
    $.fn.ceebox.popup($('#'+myDiv).html(),options);
}

function showHTML(html,options) {
    $.fn.ceebox.popup(html,options);
}

function hideWin() {
    parent.$.fn.ceebox.closebox();
}

function sk_displayByCatID(id) {
    alert('sk_displayByCatID - Nothing to be done here -> #998877');
//    $.post('./m/getSubMenuByCatID.php',{'id':id},function (data) {
//       sk_showLeftMenu(data);
//       //sk_displayContentByID(id);
//    });

}

function sk_displayContentByIDNonAjax () {
 var _objID,_postID;
    if ( (gObjID2 != '') && (gObjID2 != undefined) ) {
   	_objID = gObjID2;
    	_postID= gPostID2;
    } else {
    	_objID = gObjID;
    	_postID= gPostID;
    }
    rightInner.fadeOut(ft,function() {
        rightInner.html(loading).fadeIn(ft, function() {
            $.post('./m/getArticleByTermID.php',{'objID':_objID,'postID':_postID},function(data) {
               right.fadeIn(ft, function() {
                   rightInner.fadeIn(ft,function() {
                       rightInner.html(data);
                   });
               });

            });
        });
    });
}

function sk_showLeftMenuNoAjax() {
    $.post('./m/leftMenu.php',{'objID':gObjID,'postID':gPostID},function(data) {
       if (data.length > 2 ) {
           rightInner.animate({left:250},100,'linear', function() {
            right.animate({left:250},100,'linear', function(){
                left.fadeIn(ft, function() {
                    leftInner.html(data).fadeIn(ft);
                    if ($("#accordion").length != 0) {
                           //$("#accordion").css('height',avHeight+'px');
                           //$("#accordion").accordion({fillSpace: false});
                           $("#accordion").accordion({autoHeight:false,fillSpace:false});
                       }

                       sk_displayContentByIDNonAjax();
                });
            });//.fadeIn(ft);
           });//.fadeIn(ft);

           temp=data;
       } else {
            leftInner.fadeOut(ft, function() {
                left.html('').fadeOut(ft, function() {
                    right.animate({left:0},100,'linear');
                    rightInner.animate({left:0},100,'linear', function() {
                        sk_displayContentByIDNonAjax();
                    });
                });
            });
       }
    });
    
}

function sk_displayContentByID (objID, postID,flag) {
    document.location="index.php?objID="+gObjID+"&postID="+gPostID+"&objID2="+objID+"&postID2="+postID;
}

function sk_showLeftMenu (objID, postID, flag) {
    document.location="index.php?objID="+objID+"&postID="+postID;    
}


function sk_goBgTimer() {
    
//    var RandomBackgrounds=2;
//    var bgRand = Math.ceil(Math.random()*RandomBackgrounds);
//    var bgURL  = 'url(./themes/default/bg00'+bgRand+'.jpg';
//
//    if (diffBG=='wrapper01') {
//        diffBG='wrapper02';
//        $("#wrapper02").css('background-image',bgURL).show(0, function() {
//            $("#wrapper01").fadeOut(2000, function() {
//                setTimeout('sk_goBgTimer()',bgtransitionTimer);
//            });
//        });
//
//    } else {
//        diffBG='wrapper01';
//        $("#wrapper01").css('background-image',bgURL).show(0, function() {
//            $("#wrapper02").fadeOut(2000, function() {
//                setTimeout('sk_goBgTimer()',bgtransitionTimer);
//            });
//        });
//    }
}
