// function that writes the list order to a cookie
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
  
	  
function AddText(NewCode) {
        document.contact.message.value+=NewCode;
        document.contact.message.focus();
}
function smile(){
        AddTxt=' :)';
        AddText(AddTxt);
}
function sad(){
        AddTxt=' :(';
        AddText(AddTxt);
}
function smilehard(){
        AddTxt=' ;D';
        AddText(AddTxt);
}
function laugh(){
        AddTxt=' :D';
        AddText(AddTxt);
}
function tongue(){
        AddTxt=' :P';
        AddText(AddTxt);
}
function shocked(){
        AddTxt=' :o';
        AddText(AddTxt);
}
function cool(){
        AddTxt=' 8)';
        AddText(AddTxt);
}
function rolleyes(){
        AddTxt=' =)';
        AddText(AddTxt);
}
function wink(){
        AddTxt=' ;)';
        AddText(AddTxt);
}
function embarassed(){
        AddTxt=' :-[';
        AddText(AddTxt);
}

function saveOrder() {

    $(".column").each(function(index, value){

        var colid = value.id;

        var cookieName = "cookie-" + colid;

        // Get the order for this column.

        var order = $('#' + colid).sortable("toArray");

        // For each portlet in the column

        for ( var i = 0, n = order.length; i < n; i++ ) {

            // Determine if it is 'opened' or 'closed'

            var v = $('#' + order[i] ).find('.portlet-content').is(':visible');

            // Modify the array we're saving to indicate what's open and

            //  what's not.

            order[i] = order[i] + ":" + v;

        }

        $.cookie(cookieName, order, { path: "/", expiry: new Date(2012, 1, 1)});

    });

}



// function that restores the list order from a cookie

function restoreOrder() {

    $(".column").each(function(index, value) {

        var colid = value.id;

        var cookieName = "cookie-" + colid

        var cookie = $.cookie(cookieName);

        if ( cookie == null ) { return; }

        var IDs = cookie.split(",");

        for (var i = 0, n = IDs.length; i < n; i++ ) {

            var toks = IDs[i].split(":");

            if ( toks.length != 2 ) {

                continue;

            }

            var portletID = toks[0];

            var visible = toks[1]

            var portlet = $(".column")

                .find('#' + portletID)

                .appendTo($('#' + colid));

            if (visible === 'false') {

            }

        }

    });

}



// function that writes the list order to a cookie

// set the list selector

var setSelector = "ul.dsfsdf";

// set the cookie name

var setCookieName = "listOrder";

// set the cookie expiry time (days):

var setCookieExpiry = 7;



// function that writes the list order to a cookie

function getOrder_s() {

	// save custom order to cookie

	$.cookie(setCookieName, $(setSelector).sortable("toArray"), { expires: setCookieExpiry, path: "/" });

}

 

// function that restores the list order from a cookie

function restoreOrder_s() {

	var list = $(setSelector);

	if (list == null) return

	

	// fetch the cookie value (saved order)

	var cookie = $.cookie(setCookieName);

	if (!cookie) return;

	

	// make array from saved order

	var IDs = cookie.split(",");

	

	// fetch current order

	var items = list.sortable("toArray");

	

	// make array from current order

	var rebuild = new Array();

	for ( var v=0, len=items.length; v<len; v++ ){

		rebuild[items[v]] = items[v];

	}

	

	for (var i = 0, n = IDs.length; i < n; i++) {

		

		// item id from saved order

		var itemID = IDs[i];

		

		if (itemID in rebuild) {

		

			// select item id from current order

			var item = rebuild[itemID];

			

			// select the item according to current order

			var child = $("ul.dsfsdfss.ui-sortables").children("#" + item);

			

			// select the item according to the saved order

			var savedOrd = $("ul.dsfsdfss.ui-sortables").children("#" + itemID);

			

			// remove all the items

			child.remove();

			

			// add the items in turn according to saved order

			// we need to filter here since the "ui-sortable"

			// class is applied to all ul elements and we

			// only want the very first!  You can modify this

			// to support multiple lists - not tested!

			$("ul.dsfsdf.ui-sortable").filter(":first").append(savedOrd);

		}

	}

}



$(function() {



// dsfsdf/sortables

$(".column").sortable({

        connectWith: ['.column'],

		cursor: 'move',

		handle: 'h3',

		opacity: 0.80,

		tolerance: 'pointer',

		items: '.cat-dsfsdf',

		revert: true,

        stop: function() { saveOrder(); }

});



restoreOrder();

	

// sidebar/sortables

$(".dsfsdf").sortable({

		cursor: 'move',

		handle: 'h2',

		items: '.sd',

		opacity: 0.80,

		tolerance: 'pointer',

		revert: true,

		update: function() { getOrder_s(); }

});

	

restoreOrder_s();



// Layout options feature

$('a#options').click(function (){

	if (($('.layout_options')).is(':hidden')) {

	$('.layout_options').fadeIn('normal');

	} else {

	$('.layout_options').fadeOut('normal');

	}

});



$('.cancel a').click(function() {

	$('#wrapper').fadeTo('fast', 1.0);

	$('.layout_options').fadeOut('normal');

});



$('a#reset').click(function() {

$('.cat-dsfsdf').each( function() {$.cookie($(this).attr('id'), null, { path: '/', expires: 100 }); $(this).show()});

$('.box_a').each( function() {$.cookie($(this).attr('id'), null, { path: '/', expires: 100 }); $(this).show()});

$('.dsfsdf li').each (function() {$.cookie($(this).attr('id'), null, { path: '/', expires: 100 }); $(this).show()});

$('.layout_options').fadeOut('normal');

$('#wrapper').fadeTo('fast', 1.0);

});

// done.



// Pages Drop Down

$("#topnav ul ul").css({display: "none"}); // Opera Fix

$("#topnav li").hover(function(){

if ($(this).parent().parent().attr("id") == 'topnav') {

$(this).removeClass('active-page');

$(this).addClass('active-page');

}

$(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn(500);

},function(){

if ($(this).parent().parent().attr("id") == 'topnav') {

$(this).removeClass('active-page');

}

$(this).find('ul:first').css({visibility: "hidden"});

});

// End



// Categories Drop Down

$("#menu ul ul").css({display: "none"}); // Opera Fix

$("#menu li").hover(function(){

if ($(this).parent().parent().attr("id") == 'menu') {

$(this).removeClass('active-cat');

$(this).addClass('active-cat');

}

$(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn(500);

},function(){

if ($(this).parent().parent().attr("id") == 'menu') {

$(this).removeClass('active-cat');

}

$(this).find('ul:first').css({visibility: "hidden"});

});

// End







$('.dsfsdf li').each (function() {

	var sidebar_ID = $(this).attr('id');

	if ($.cookie(sidebar_ID) == 'closed') $(this).hide();

});



/* clear form */

$('.clearfield').each(function() {

    var default_value = this.value;

    $(this).css('color', '#666'); // this could be in the style sheet instead

    $(this).focus(function() {

        if(this.value == default_value) {

            this.value = '';

        }

    });

    $(this).blur(function() {

        if(this.value == '') {

            this.value = default_value;

        }

    });

});



// video thumbs

$('.videothumb').bind('mouseenter', function() {$(this).children('.playit').children('a').show()});

$('.videothumb').bind('mouseleave', function() {$(this).children('.playit').children('a').hide()});



// more stories

$('ul.more_stories li').css({'display': 'none'});

$("ul.more_stories").each(function(){

$(this).children('li').slice(0, 3).show();

});



/* control visible stories */

$('.minus').click(function() {

$(this).parent().next('ul').children('li:visible:last').hide();

});



$('.plus').click(function() {

$(this).parent().next('ul').children('li:hidden:first').show();

});



// append top menu

$("#topnav ul:first").prepend('<li class="left"></li>');

$("#topnav ul:first").append('<li class="right"></li>');



// featured 1

$("span.overlay").fadeTo(1, 0.70);

$("ul.items").tabs(".pane", {

	effect: "fade",

	fadeInSpeed: 500,

	fadeOutSpeed: 500,

	rotate: true

}).slideshow({autoplay: true, interval: 4000, clickable: false});

	

// featured 2

$("ul.featuredposts").tabs(".featuredposts_content", {

	effect: "default",

	rotate: true

}).slideshow({autoplay: true, interval: 4000, clickable: false});



});
jQuery(document).ready(function(){lightsoff();});


function validate_form3(form)
{
if (form.title.value == "") {
   alert('يجب كتابة الاسم');
    form.title.focus();
    return false ;
  }
  
  if (form.massage.value == "") {
   alert('يجب كتابة الاهداء');
    form.massage.focus();
    return false ;
  } 
  if (form.captcha.value == "") {
   alert('يجب كتابة الحروف الموجوة فى الصورة');
    form.captcha.focus();
    return false ;
  }
else
return true ;
}
//-->

