$(document).ready(function(){
    
    //send Friend
    $('#sendFriend').click(function(e){
        e.preventDefault();
        $('#sendFriend-close').click(function(){$.modal.close();});
        
        $('#sendFriendForm').modal({
            opacity:80,
            closeClass:'simplemodal-close-friend',
            overlayCss: {backgroundColor:"#000"}
        });
    });
    
    var sendFriendBlock=$('#sendFriend-block');
    var options = {
        beforeSubmit: function(formData, jqForm, options) {
            sendFriendBlock.html('Sending Email...').show();
        },
        success:    function(responseText, statusText, xhr, $form)  {
            var result='';
                        
            if(responseText=='OK'){
                result='Thank you for joining our E-Mail Exclusives mailing list.';
            }
            else{
                result=responseText;
            }
            sendFriendBlock.html(result);

            $('#sendFriend-form').clearForm();
        }
    };
    // pass options to ajaxForm
    $('#sendFriend-form').ajaxForm(options);
    
    
    ///Newsletter
   var  dialofNews=$('<div id="newsletter-dialog" title="Newsletter Status"></div>');
    dialofNews.dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        draggable: false,
        buttons: {
            "OK": function() {
                $( this ).dialog( "close" );
            }
        },
        minHeight: 150
    });

    var options = {
        beforeSubmit: function(formData, jqForm, options) {
            dialofNews.html('Sending Email...').show();
            dialofNews.dialog( "open" );
        },
        success:    function(responseText, statusText, xhr, $form)  {
            var result='';
            dialofNews.dialog( "open" );
            
            if(responseText=='OK'){
                result='Thank you for joining our E-Mail Exclusives mailing list.';
            }
            else{
                result=responseText;
            }
            dialofNews.html(result);

            $('.newsletterForm').clearForm();
        }
    };
    // pass options to ajaxForm
    $('.newsletterForm').ajaxForm(options);

    $('.newsletterForm input[type=text]').focus(function(){this.value='';})
    
    if($("#service-tree").length==1){
        $('#service-tree li').addClass('closed');
        
        var url=location.href.split('/');
        url=url[(url.length-1)];
        
        var href=false;
        $('#service-tree a').each(function(){
            href=$(this).attr('href')
            href=href.split('/');
            href=href[(href.length-1)];
            
            if(href==url){
                $(this).parents('li').removeClass('closed');
            } 
        });
        
        $("#service-tree").treeview();
        
    } 
});


function langPopup(){
    $('#langPopup').modal({
	opacity:80,
	overlayCss: {backgroundColor:"#000"}
    });
}
