//AUGUST 15 2011

// JQUERY DEFAULT 

$(function(){
    $('.dia_hi_lnk').click(function(){
        $.ajax({
            type:'GET',
            url:'termAndConditionAjax.action?now='+new Date(),
            dataType:'html',
            beforeSend:function(){
            },
            success:function(msg){
                targetSelect=msg;
                document.getElementById("dia_hiterm").innerHTML =msg;
                $('#dia_hiterm').dialog('open');
            },
            error:function(r,t,e){
            }
        });

        return false;
    });


// ACCORDION

$("#accordion").accordion({ header: "h3" });

// TABS

$('.tab_log').tabs();

$('.tab_m').tabs();

// DATEPICKER

//$('.date').datepicker({inline: true});
				
// SLIDER

$('#slider').slider({
    range: true,
    values: [17, 67]
});
				
// PROGRESSBAR

$("#progressbar").progressbar({
    value: 20
});
				
// HOVER STATES ON THE STATIC WIDGETS

$('#dialog_link, ul#icons li').hover(
function() { $(this).addClass('ui-state-hover'); }, 
function() { $(this).removeClass('ui-state-hover'); }
);	

});

$(function() {
$( "#radio" ).buttonset();
});

// DIALOGS 

$(function(){

// DIALOG 0		

$('#dia0').dialog({
    autoOpen: false,
    width: 600,
    buttons: {
        "Send": function() { $(this).dialog("close"); },
        "Cancel": function() { $(this).dialog("close"); }
    }
});
$('.dia0_lnk').click(function(){
    $('#dia0').dialog('open'); return false;
});

// DIALOG 1			

$('#dia1').dialog({
    autoOpen: false,
    width: 600
});
$('.dia1_lnk').click(function(){
    $('#dia1').dialog('open'); return false;
});

});

// PLUS 

$(function() {

// AVOID GO TO TOP		   

$('.notop').click (function() { return false; });

// BACK

$('.back').click (function() { history.go(-1); });

});

// MENU

$(document).ready(function(){

$(".topnav li span ").mouseover(function() { //When trigger is clicked...

    //Following events are applied to the subnav itself (moving subnav up and down)

    $(this).parent().find("ul.subnav").show(); //Drop down the subnav on click

    $(this).parent().hover(function() {
    }, function(){
        $(this).parent().find("ul.subnav").hide(); //When the mouse hovers out of the subnav, move it back up
    })
})
});

// HOME SLIDE SHOW

$(document).ready(function(){
						   
$('#slideshow1').cycle({
    timeout: 2000,
    speed: 1
})

$('#slideshow2').cycle({
    timeout: 3000,
    speed: 200
})

$('.slide3').cycle({
    timeout: 3000,
    speed: 200
})

});


// MENU TOP LANGUAGES

$(document).ready(function(){

$(".men_lan li a ").click(function() { //When trigger is clicked...

    //Following events are applied to the subnav itself (moving subnav up and down)

    $(this).parent().find(".sub_lan").show(); //Drop down the subnav on click

    $(this).parent().hover(function() {}, function(){
        $(this).parent().find(".sub_lan").hide(); //When the mouse hovers out of the subnav, move it back up
    })
})
});

//SEXY LIGHTBOX

$(document).ready(function(){
SexyLightbox.initialize({
    find          : 'sexylightbox', // rel="sexylightbox"
    color         : 'black',
    dir           : 'js/box/sexyimages',
    emergefrom    : 'top',
    OverlayStyles : {
        'background-color': '#000000',
        'opacity' : 0.7
    }
});
});

// TOOLTIP

$(function() {
$('.tip').tipsy({
    gravity: 'w',
    title:'rel',
    fade:true
});
});

// TOOLTIP FOR BUTTON ELEMENTS

$(function() {
$('.tipp').tipsy({
    gravity: 'sw',
    title:'alt',
    fade:true
});
});

// TOOLTIP FOR INPUT ELEMENTS

$(function() {
$('.tippp').tipsy({
    gravity: 'sw',
    title:'title',
    fade:true
});
});

// TOOLTIP FOR LIST

$(function() {
$('.tips').tipsy({
    gravity: 'w',
    title:'rel',
    html:true,
    fade:true
});
});

// TOOLTIP FOR LIST ARABIC

$(function() {
$('.tips_ar').tipsy({
gravity: 'e',
title:'rel',
html:true,
fade:true
});
});

// TOOLTIP LIST BIG

$(function() {
$('.tip_big').tipsy({
    gravity: 'w',
    title:'rel',
    html:true,
    fade:true
});
});

// TOOLTIP OVER

$(function() {
$('.tip_a').tipsy({
    title:'rel',
    html:true,
    fade:true
});
});

// TOOLTIP INPUT ON CLICK

$(function() {
$('.tip_inp [title]').tipsy({
    trigger: 'focus',
    gravity: 'w'
});
});


// TOGGLE SHOW HIDE

$(document).ready(function() {
$('.tog_lnk').click(function(){
    $('#tog').toggle();
});
});

// SHOW HIDE LINK

$(document).ready(function() {
$('#sh_hi').hide();
$('a.sh_hi_lnk').click(function() {
    var id = $(this).attr('id');
    $('#sh_hi' + id).toggle();
    // alert(id);
    return false;
});
}); 

$(document).ready(function() {
$('#sh_hia').hide();
$('a.sh_hia_lnk').click(function() {
    var id = $(this).attr('id');
    $('#sh_hia' + id).toggle();
    // alert(id);
    return false;
});
}); 

// DIALOG MULTIPLE

$(document).ready(function() {
$('#dia_ha').hide();
$('.dia_ha_lnk').click(function() {
    var id = $(this).attr('name');
    $('#dia_ha' + id).dialog(
    {
        width: 600,
        buttons: {
            "submit": function() { $(this).dialog("close"); },
            "cancel": function() { $(this).dialog("close"); }
        }
    }); return false;
});
}); 

$(document).ready(function() {
$('#dia_he').hide();
$('.dia_he_lnk').click(function() {
    var id = $(this).attr('name');
    $('#dia_he' + id).dialog(
    {
        width: 600,
        buttons: {
            "back": function() { $(this).dialog("close"); },
            "next": function() { $(this).dialog("close"); }
        }
    }); return false;
});
}); 

$(document).ready(function() {
$('#dia_hi').hide();
$('.dia_hi_lnk').click(function() {
    var id = $(this).attr('rel');
    $('#dia_hi' + id).dialog(
    {
        width: 600,
        buttons: {
            "X": function() { $(this).dialog("close"); }
        }
    }); return false;
});
}); 

// DIALOG MULTIPLE WIDER

$(document).ready(function() {
$('#dia_hi_w').hide();
$('.dia_hi_lnk_w').click(function() {
    var id = $(this).attr('rel');
    $('#dia_hi_w' + id).dialog(
    {
        width: 800,
        buttons: {
            "X": function() { $(this).dialog("close"); }
        }
    }); return false;
});
}); 

$(document).ready(function() {
$('#dia_w').hide();
$('.dia_lnk_w').click(function() {
    var id = $(this).attr('name');
    $('#dia_w' + id).dialog(
    {
        width: 1100,
        modal: true,
        buttons: {
            "back": function() { $(this).dialog("close"); },
            "next": function() { $(this).dialog("close"); }
        }
    }); return false;
});
}); 

$(document).ready(function() {
$('#dia_cl').hide();
$('.dia_lnk_cl').click(function() {
    var id = $(this).attr('name');
    $('#dia_cl' + id).dialog(
    {
        width: 1024,
        buttons: {
            "X": function() { $(this).dialog("close"); }
        }
    }); return false;
});
}); 


// SELECTED ITEM

$(function() {
$( '.sel_m' ).selectable();
});

$(document).ready(function() {
$('.sel').selectable({
    stop: function(e, ui) {
        $(".ui-selected:first", this).each(function() {
            $(this).siblings().removeClass("ui-selected");
            var refreshVal = $(this).attr("value");
        });
    }
});
});

// TEMPLATES PREVIEW TOOLTIP

$(document).ready(function(){
$('.prev li img').tooltip({ 
    delay: 0,
    showURL: false,
    bodyHandler: function() {
        return $("<img/>").attr("src", this.src);
    }
});
});

// CREATE NEW ITEM

$(function() {
		   
var name = $( "#name" ),
allFields = $( [] ).add( name ),
tips = $( ".validateTips" );

function updateTips( t ) {
    tips
    .text( t )
    .addClass( "ui-state-highlight" );
    setTimeout(function() {
        tips.removeClass( "ui-state-highlight", 1500 );
    }, 500 );
}

function checkLength( o, n, min, max ) {
    if ( o.val().length > max || o.val().length < min ) {
        o.addClass( "ui-state-error" );
        updateTips( "Length of " + n + " must be between " +
            min + " and " + max + "." );
	return false;
    } else {
	return true;
    }
}

function checkRegexp( o, regexp, n ) {
    if ( !( regexp.test( o.val() ) ) ) {
	o.addClass( "ui-state-error" );
	updateTips( n );
	return false;
    } else {
	return true;
    }
}
		
$( "#dialog-form" ).dialog({
    autoOpen: false,
    height: 150,
    width: 350,
    buttons: {
        "+": function() {
            var bValid = true;
            allFields.removeClass( "ui-state-error" );

            bValid = bValid && checkLength( name, "link name", 3, 16 );
			
            bValid = bValid && checkRegexp( name, /[a-z]([0-9a-z_])+$/i, "link name may consist of a-z, 0-9, underscores, begin with a letter." );
					
            if ( bValid ) {
                $( "#users" ).append( "<li>" + "<span class='ui-icon ui-icon-close'>Remove Tab</span>" + name.val() +"</li>" );
                $( this ).dialog( "close" );
            }
        },
        "x": function() {
            $( this ).dialog( "close" );
        }
    },
    close: function() {
        allFields.val( "" ).removeClass( "ui-state-error" );
    }
});

$( "#create-user" )
.button()
.click(function() {
    $( "#dialog-form" ).dialog( "open" );
});

$( "#users span.ui-icon-close" ).live( "click", function() {
    var index = $( "li").index( $( this ).parent("#users li").remove() );
});

});



$(function() {  $('.tab_m').tabs(); 

$('.sh_2').click(function(event) {    
    $('.tab_m').tabs('select', 1);  })

$('.sh_3').click(function(event) {    
    $('.tab_m').tabs('select', 2);  })

$('.sh_4').click(function(event) {    
    $('.tab_m').tabs('select', 3);  })

$('.sh_5').click(function(event) {    
    $('.tab_m').tabs('select', 4);  })

$('.sh_6').click(function(event) {    
    $('.tab_m').tabs('select', 5);  })

$('.sh_7').click(function(event) {    
    $('.tab_m').tabs('select', 6);  })

$('.sh_8').click(function(event) {    
    $('.tab_m').tabs('select', 7);  })

$('.sh_9').click(function(event) {    
    $('.tab_m').tabs('select', 8);  })

});



