
/* Main Menu */
var defalt;
var released;
var alive=false;
var timeOut=null;

function MainTopMenu() {
    //first time on load the page
    //get the default menu to be selected
    defalt=$(defaultMainMenu);
    released=defalt;
    baseMenu();
	$("#head_main_menu ul li a").mouseover(function() {
		clearTimeout(timeOut);
		if($(this).attr("class")=="checked") return;

		$(released).attr("class","unchecked");
		var subMenu3 = $($($(released).parent()).attr("submenu"));

		$(".bottom_menu_line").hide();

		//subMenu3.hide();//("slow");
		var subMenu = $($($(this).parent()).attr("submenu"));
		subMenu.fadeIn("slow");

		$(this).attr("class","checked");
		released=$(this);
	}).mouseout(function() {
		if($(defalt).attr("class")=="checked") return;
		timeOut=setTimeout(baseMenu,1000);
	});

	$(".bottom_menu_line").mouseover(function() {
		clearTimeout(timeOut);
	}).mouseout(function() {
		timeOut=setTimeout(baseMenu,1000);
	});
}

function baseMenu() {
	if($(defalt).attr("class")=="checked") return;
	var subMenu = $($(released).parent().attr("submenu"));
	var subMenu2 = $(defalt.parent().attr("submenu"));

	released.attr("class","unchecked");
	//subMenu.fadeOut("slow");
	$(".bottom_menu_line").hide();

	defalt.attr("class","checked");
	subMenu2.fadeIn("slow");
	released=defalt;
}






            var deleteItemCounter = 0;

            $(function() {
                $('.file_item').each(function() {
                    
                    var id = 'delete_item_'+(deleteItemCounter++);
                    var link = $(this).attr('delete_href');
                    $("#mani_layout").append('<a href="#deletIcon" onclick="conDel(\''+link+'\');" id="'+id+'" class="delete_icon" ></a>');
                    var offset = $(this).parent().offset() ;
                    offset.top +=1;
                    if(LANG == 'en') {
                        $('#'+id).css( {top:offset.top} );
                    } else {
                        $('#'+id).css( {top:offset.top,left:offset.left-135} );
                    }
                    
                })
            });

confirmMsg = {ar:"هل تريد متابعة عملية الحذق؟",en:"are you sure that you would like to delete this ?"};
function conDel(url) {
    if(confirm(confirmMsg[LANG])) {
        window.location = url;
    }
}


/* gallary */
var images_counter = 0;
var images_length = 0;
var gallery_interval = null;
var galleryTranslationIsOn=false;
function slideSwitch(whereto) {
    if(galleryTranslationIsOn || whereto==images_counter)
          return;
    var $active = $('#slideshow IMG.active');
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');

    if(whereto!=undefined ) {
        clearInterval(gallery_interval);
        var img = $('#slideshow IMG');
        $next = $(img[whereto]);
        images_counter=whereto-1;

        gallery_interval = setInterval( "slideSwitch()", 5000 );
    }
    $active.addClass('last-active');

    var next = (images_counter+1 == images_length) ? 0 : images_counter+1;
    $('.__gallery_menu_link').removeClass('active');
    $(".__slideshow_menu_"+next ).addClass('active');
    galleryTranslationIsOn=true;

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');

            images_counter = (images_counter+1 == images_length) ? 0 : images_counter+1;
            galleryTranslationIsOn=false;
        });
}

function runGallery() {
    $('#slideshow IMG:first').addClass('active');

    images_length = $('#slideshow IMG').length;
    var html = '';
    for(var i=0;i<images_length;i++) {
        var active=(i==0)?'active ':'';
        html += '<li><a href="javascript:void(0)" class="__slideshow_menu_'+i+' __gallery_menu_link '+active+'" onclick="slideSwitch('+i+')"></a></li>';
    }
    $('.__top_main_menu').html(html);
    $('#slideshow IMG').each(function() { $(this).css({opacity:0,visibility:'visible'}); });
    $('#slideshow IMG.active').css({opacity:100});
    gallery_interval = setInterval( "slideSwitch()", 5000 );
}


function videoAd(no) {
    window.open(PATH+"/misc/video.html",'_blank',"status=0,toolbar=0,resizable=0,menubar=0,scrollbars=0,height=439,width=553");
    //window.open(PATH+"/misc/video.html", "Palwork - videos", "status=0,toolbar=0,resizable=0,menubar=0,scrollbars=0,height=439,width=553");
    return;
    var flashObject = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/ZOCeW2Pu3Q8&hl=en&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ZOCeW2Pu3Q8&hl=en&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
    var backLink = '<a href="javascript:closeVid()">Back</a>'
    $('.right_content').css({position:'relative'});
    $('.right_content').append('<div id="video_dialog"></div><div id="video_content"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td valign="top" align="center">'+flashObject+'</td></tr><tr><td align="left">'+backLink+'</td></tr></table></div>');
    $('#video_content').hide();

    $("#video_dialog").css({opacity: 0});
    $("#video_dialog").animate({opacity: 0.80}, 700, function() {
        $('#video_content').show();
    });
}
function closeVid() {
    $("#video_dialog").remove();
    $("#video_content").remove();
}

/*$(function() {
    var w = $(document).width();
    var h = $(document).height();
    $('body,html').css({overflow:'hidden'});
    $('#shade').append('<div style="width:'+w+'px; height:'+h+'px; background:#000; position:absolute; top:0; left:0; z-index:9999;opacity:0.5"></div>');

});*/



function adminMenu() {
    
        if(LANG=='ar'){
            $("ul.subnav").parent().prepend("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
        } else {
            $("ul.subnav").parent().prepend("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
        }

	$("ul.topnav li span").click(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		$(this).parent().hover(function() {
		}, function(){
                    $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
}

