var flashIntro = '<object width="800" height="460" align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" name="introduction_09_10_2011" id="introduction_09_10_2011" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"><param value="https://www.darioush.com/assets/flash/introduction_09_10_2011.swf?soundFile=loop.mp3" name="movie"> <param value="high" name="quality"> <param value="#95b4c3" name="bgcolor"> <param value="sameDomain" name="allowscriptaccess"> <embed width="800" height="460" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowscriptaccess="sameDomain" name="introduction_09_10_2011" bgcolor="#95b4c3" quality="high" src="https://www.darioush.com/assets/flash/introduction_09_10_2011.swf?soundFile=loop.mp3" id="introduction_09_10_2011"></object>';
var bgPlayer,soundPlayer;

var audioSupport;

try{
  new Audio();
  audioSupport = true;
}
catch(err)
{
  audioSupport = false;
}
  

var clientSettings = {
    hasFlashSupport:FlashDetect.installed,
    hasAudioSupport: audioSupport,
    isSafari : navigator.userAgent.toLowerCase().indexOf("safari")!=-1,
    isIphone : (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)),
    isHomePage:true
}


        
function setCookie(c_name,value,exdays){
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()) + "; path=/";
    document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name){
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}


window.addEvent('domready', function(){

    window.addEvent("resize",vertical_center);
    vertical_center();
    $("flash_footer").setStyle("display","block").removeClass("loadingAtStart");

    if(clientSettings.hasFlashSupport){
        $('flashReplace').innerHTML=flashIntro;
        $("header").setStyle("padding-left","30px");
        $$("#header a").removeClass("loadingAtStart");
        $("bottom_footer").removeClass("loadingAtStart");
    }
    else {
        bgPlayer = new bgMusic();
        bgPlayer.init();
        if(clientSettings.hasAudioSupport){
        soundPlayer = new audioPlayer();
        soundPlayer.init(20);
        }
        loading_sequence();
    }
});

window.addEvent('load', function(){
    if(!clientSettings.hasFlashSupport){
        if(getCookie("playerMuted")!="1")
            if(bgPlayer!=undefined)
                bgPlayer.togglePlaying();
    }
});


function loading_sequence(){

        // FADE IN MAIN CONTAINER
        setTimeout(function(){
            new Fx.Tween($("main"), {
              duration: 1000,
              property: 'opacity',
              onComplete : function(){

                  $("main").removeClass("loadingAtStart");
              }
            }).start(0,1);
        },0);
        // END MAIN CONTAINER 
        // 
        // FADE IN PLAYER
        if(clientSettings.hasAudioSupport || clientSettings.hasFlashSupport)
            setTimeout(function(){
                new Fx.Tween($("player"), {
                  duration: 1000,
                  property: 'opacity',
                  onComplete : function(){

                      $("player").removeClass("loadingAtStart");
                  }
                }).start(0,1);
            },0);
        // END PLAYER

        // FADE IN TOP NAVIGATION
        setTimeout(function(){
            new Fx.Tween($("facebook_link"), {
              duration: 300,
              property: 'opacity',
              onComplete : function(){

                  $("facebook_link").removeClass("loadingAtStart");
              }
            }).start(0,1);
        },1000);

        setTimeout(function(){
            new Fx.Tween($("cart"), {
              duration: 300,
              property: 'opacity',
              onComplete : function(){

                  $("cart").removeClass("loadingAtStart");
              }
            }).start(0,1);
        },1300);


        setTimeout(function(){
            new Fx.Tween($("login"), {
              duration: 300,
              property: 'opacity',
              onComplete : function(){

                  $("login").removeClass("loadingAtStart");
              }
            }).start(0,1);
        },1600);



        // END TOP NAVIGATION //

        // FADE IN FOOTER NAVIGATION
        setTimeout(function(){
            new Fx.Tween($("footer"), {
              duration: 500,
              property: 'opacity',
              onComplete : function(){

                  $("footer").removeClass("loadingAtStart");
              }
            }).start(0,1);
        },2200);
        // END FOOTER NAVIGATION //

        // FADE IN SLIDESHOW
        setTimeout(function(){
            new Fx.Tween($("slideshow"), {
              duration: 500,
              property: 'opacity',
              onComplete : function(){

                  $("slideshow").removeClass("loadingAtStart");
                  // INITIALIZE SLIDESHOW //
                  slideShow.init({
                      direction:"normal",
                      duration : 7,
                      fadeTime :3
                  });
              }
            }).start(0,1);
        },2700);
        // END SLIDESHOW //
        // 
        // FADE IN LEFT IMAGE
        setTimeout(function(){
            new Fx.Tween($("left_image"), {
              duration: 300,
              property: 'opacity',
              onComplete : function(){

                  $("left_image").removeClass("loadingAtStart");
              }
            }).start(0,1);
        },3200);
        // END LEFT IMAGE //

        // FADE IN SIDEBAR NAVIGATION
        setTimeout(function(){
            new Fx.Tween($("side-menu"), {
              duration: 500,
              property: 'opacity',
              onComplete : function(){

                  $("side-menu").removeClass("loadingAtStart");

                  // INITIALIZE SIDE MENU //
                  sideMenu.init();

              }
            }).start(0,1);
        },3500);
        // END SIDEBAR NAVIGATION //
        // 
        // FADE IN POPUPS
        var popups = $$("div.popup");

        var first_popup = popups[0];

        setTimeout(function(){
            new Fx.Tween(first_popup, {
              duration: 300,
              property: 'opacity',
              onComplete : function(el){

                  first_popup.removeClass("loadingAtStart");
              }
            }).start(0,1);
        },3800 );

        var second_popup = popups[1];

        setTimeout(function(){
            new Fx.Tween(second_popup, {
              duration: 300,
              property: 'opacity',
              onComplete : function(el){

                  second_popup.removeClass("loadingAtStart");

              }
            }).start(0,1);
        },4100 );

        var third_popup = popups[2];

        setTimeout(function(){
            new Fx.Tween(third_popup, {
              duration: 300,
              property: 'opacity',
              onComplete : function(el){

                  third_popup.removeClass("loadingAtStart");

                  // INITIALIZE POPUPS //
                  popOuts.init();

              }
            }).start(0,1);
        },4400 );

        // END POPUPS //
        
        // FADE IN BOTTOM FOOTER
        
        setTimeout(function(){
            new Fx.Tween($("bottom_footer"), {
              duration: 300,
              property: 'opacity',
              onComplete : function(el){

                  $("bottom_footer").removeClass("loadingAtStart");

              }
            }).start(0,1);
        },4700 );
        
        setTimeout(function(){
            new Fx.Tween($("flash_footer"), {
              duration: 300,
              property: 'opacity',
              onComplete : function(el){

                  $("flash_footer").removeClass("loadingAtStart");

              }
            }).start(0,1);
        },4700 );
        
        
       

}

function get_group_type_by_id(groupid){
       var grptypes="";
       
       $.get("cms/cms_get_ad_group_type_by_group_id.php", { "gid": groupid },
  function(data){
   // alert(data.gtype); // John
    console.log(data.gtype); //  2pm
        grptypes=data.gtype;
       
          }, "json");
         
          return "NE";
               
       
}


function show_advert_by_group_id(groupid){
       $.get("cms/cms_get_ad_group_type_by_group_id.php", { "gid": groupid },
        function(data){
           alert (data.gtype);
        }, "json");
}

function vertical_center(){
    
    var window_y= window.getSize().y;
    
   if(window_y>560){
       
       var offset = (window_y - 560)/2 ;
       $("wrappper").setStyle("margin-top",(offset)+"px");
       $("bottom_footer").setStyle("margin-top",(offset+50)+"px");
       
   }
   else {
        $("wrappper").setStyle("margin-top","0px");
        $("bottom_footer").setStyle("margin-top","0px");
   }
    
}

 function preloadImage(href) { 
     if(!window.preloadImageList) window.preloadImageList = new Array(); 
     var i = window.preloadImageList.length; 
 
     window.preloadImageList[i] = new Image(); 
     window.preloadImageList[i].src = href; 
}
