/*=================================================================================*/
/*convert fonts*/
/*=================================================================================*/
FLIR.init({
    path:'js/facelift/'
});
FLIR.replace('div#omar', new FLIRStyle({
    cFont:'gothambook'
}));
FLIR.replace('div.contact_label', new FLIRStyle({
    cFont:'gothambook'
}));
FLIR.replace('a#contact_spam_reload', new FLIRStyle({
    cFont:'gothambook',cColor:'#71d4ff'
}));
FLIR.replace('div.main_category_link', new FLIRStyle({
    cFont:'gothambook'
}));
FLIR.replace('div.sub_category_link', new FLIRStyle({
    cFont:'gothambook'
}));


/*=================================================================================*/
/*right click disable*/
/*=================================================================================*/
function clickIE4(){
         if (event.button==2){
         alert(message);
         return false;
         }
}
function clickNS4(e){
         if (document.layers||document.getElementById&&!document.all){
             if (e.which==2||e.which==3){
                 alert(message);
                 return false;
             }
         }
}
if (document.layers){
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
     document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("return false")

/*=================================================================================*/
/*check mail for validation*/
/*=================================================================================*/
function checkMail(valMail){
    var ismail=true;
    var filter =/^.+@.+..{2,3}$/;
    if (!filter.test(valMail))
        ismail=false
    return ismail;
}

/*=================================================================================*/
/*empty check for validation*/
/*=================================================================================*/
function trim(str){
    var str=str.replace(new RegExp("^[\\s]+", "g"),"");
    str=str.replace(new RegExp("[\\s]+$", "g"), "");
    return str;
}

/*=================================================================================*/
/*validation action There must be a problem. Check if you have correctly filled out the required fields:*/
/*=================================================================================*/
function validate() {
    jQuery("#validation_msg").slideUp();
    jQuery("#validation_msg").html('');
    err='';
    if (!trim(jQuery("#contact_name").val())){
        err+="<li>Please tell me your full name.</li>";
    }
    if (!checkMail(jQuery("#contact_email").val())){
        err+="<li>Please enter a valid e-mail address.</li>";
    }
    if (!trim(jQuery("#contact_subject").val())){
        err+="<li>Please let me know what the subject is.</li>";
    }
    if (!trim(jQuery("#contact_comment").val())){
        err+="<li>Please let me know what your message is.</li>";
    }
    if (!trim(jQuery("#contact_spam").val())){
        err+="<li>Please type in the verification code.</li>";
    }
    if (err>''){
        jQuery("#validation_msg").css({color:'#7c7c7c'});
        jQuery("#validation_msg").append("<div class='fail'>There must be a problem.</div>");
        jQuery("#validation_msg").append("<ol>" + err + "</ol>");
        jQuery("#validation_msg").slideDown();
        return false;
    }
    else{
        jQuery("#validation_msg").slideDown();
        jQuery("#validation_msg").html("<div class='data'>please wait sending message</div>");
        jQuery("#contact_send").attr('disabled',true);
        jQuery("#contact_clear").attr('disabled',true);
        jQuery.ajax({
                        async:false,
                        type: "POST",
                        url: "include.php",
                        data:"sendmail=send"+"&contact_name="+jQuery("#contact_name").val()
                                            +"&contact_email="+jQuery("#contact_email").val()
                                            +"&contact_subject="+jQuery("#contact_subject").val()
                                            +"&contact_comment="+jQuery("#contact_comment").val()
                                            +"&contact_spam="+jQuery("#contact_spam").val(),
                        success: function(result){
                           var result=eval('(' + result + ')');
                           jQuery("#validation_msg").html(result.data);
                           jQuery("#validation_msg").slideDown();
                           if(result.operation=='sucess'){
                                form_clear();
                           }
                           jQuery("#contact_spam_reload").click();
                           jQuery("#contact_send").attr('disabled',false);
                           jQuery("#contact_clear").attr('disabled',false);
                        },
                        error: function(){
                            alert('Error loading');
                            jQuery("#validation_msg").slideUp();
                        }
          });

    }

}

/*=================================================================================*/
/*form clear*/
/*=================================================================================*/
function form_clear(){
    jQuery('#contactus').find('input,textarea').val('');
}

/*=================================================================================*/
/*input styling*/
/*=================================================================================*/
function input_style(){
    jQuery('.contact_input').bind('focus',function(){
        jQuery(this).css({
            border:'2px solid #2ca9df'
        });
        jQuery(this).css({
            background:'#ffffff'
        });
        jQuery(this).css({
            margin:'0px'
        });
        jQuery(this).css({
            color:'#7c7c7c'
        });

    })
    jQuery('.contact_input').bind('blur',function(){
        jQuery(this).css({
            border:'1px solid #2ca9df'
        });
        jQuery(this).css({
            background:'#7c7c7c'
        });
        jQuery(this).css({
            margin:'1px'
        });
        jQuery(this).css({
            color:'#ffffff'
        });
    })
}

/*=================================================================================*/
/*menu click*/
/*=================================================================================*/
function menu_click(id){
    id=id.replace('#','');
    jQuery('#'+id).attr('class',id+'_selected');
    jQuery('.primary a').each(function(){
    if(id!=$(this).attr('id'))
            jQuery(this).attr('class',$(this).attr('id'));
   })
   form_clear();
}

function set_section_height(){
    if(jQuery(window).height()>600){
        jQuery("#content").height(jQuery(window).height()-jQuery("#copyright").height());
        jQuery("#omar").height(jQuery("#content").height());
        jQuery("#portfolio").height(jQuery("#content").height());
        jQuery("#contactus").height(jQuery("#content").height());
        jQuery("html",document.parent).css("overflow-y","hidden");
    }
    else{
        jQuery("#content").height(588);
        jQuery("#omar").height(jQuery("#content").height());
        jQuery("#portfolio").height(jQuery("#content").height());
        jQuery("#contactus").height(jQuery("#content").height());
        jQuery("html",document.parent).css("overflow-y","auto");
    }

}
/*=================================================================================*/
/*height manipulate*/
/*=================================================================================*/
jQuery(window).resize(function(){
    jQuery('#loading').height(jQuery(window).height());
    jQuery('#loading').width(jQuery(window).width());
    set_section_height();
});

/*=================================================================================*/
/*styling the input of all sites especially contact us please go check the function*/
/*=================================================================================*/
 input_style();
 
/*=================================================================================*/
/*omar menu click/
/*=================================================================================*/
jQuery("#omar_menu").bind('click',function(){
        if(jQuery("#omar").css('visibility')=='hidden'){
            jQuery('#omar').css({'display':'none'})
            jQuery('#omar').css({'visibility':'visible'})
            jQuery('#omar').slideDown();
        }
});

/*=================================================================================*/
/*spam checker/
/*=================================================================================*/
    jQuery("#contact_spam_reload").click(function(){
        jQuery('#contact_spam_img').attr('src','include.php?checkspam=reload&'+Math.random());
        jQuery('#contact_spam_img').hide(200);
        jQuery.ajax({
            type: "GET",
            url: "include.php",
            data:"spamreload=sleep",
            success: function(result){
                jQuery('#contact_spam_img').show(400);
            },
            error: function(){
                alert('cant load');
            }
        });
    }).bind('mouseover',function(){
        jQuery(this).css({
            backgroundPosition:'0px -17px'
        });
    }).bind('mouseout',function(){
        jQuery(this).css({
            backgroundPosition:'0px 0px'
        });
    })

/*=================================================================================*/
/*contact buttons*/
/*=================================================================================*/
    jQuery('#contact_clear').bind('click',function(){
        form_clear();
    }).bind('mouseover',function(){
        jQuery(this).css({
            backgroundPosition:'0px -11px'
        });
    }).bind('mouseout',function(){
        jQuery(this).css({
            backgroundPosition:'0px 0px'
        });
    })
    jQuery('#contact_send').bind('click',function(){
        validate();
    }).bind('mouseover',function(){
        jQuery(this).css({
            backgroundPosition:'0px -11px'
        });
    }).bind('mouseout',function(){
        jQuery(this).css({
            backgroundPosition:'0px 0px'
        });
    })

/*=================================================================================*/
/*automcomplete off for all  inputs*/
/*=================================================================================*/
    jQuery("input").attr('automplete','off');

/*=================================================================================*/
/*actions set on document ready*/
/*=================================================================================*/
jQuery(document).ready(function(){
    //if(jQuery.browser.mozilla)

    /*=================================================================================*/
    /*loading_omar_pic set*/
    /*=================================================================================*/
    jQuery('#loading_omar_pic').show().css({
        opacity:0
    }).animate({
        opacity:1
    }, 1000);
    jQuery('#loading_omar_pic').bind('click',function(){
        jQuery('#loading').hide();
        jQuery('#loading').html('');
        jQuery('.container').css({
            visibility:'visible'
        });
        jQuery('.container').show().css({
            opacity:0
        }).animate({
            opacity:1
        }, 1000);
    });
    /*=================================================================================*/
    /*main category hover*/
    /*=================================================================================*/
   jQuery('.sub_category_content').hide();
  
   jQuery('.main_category_hover').bind('mouseover',function(){
        jQuery('.main_category').children('div:first-child').show();
        jQuery('.main_category').children('div:last-child').hide();
        jQuery(this).next().children('div:first-child').hide();
        jQuery(this).next().children('div:last-child').show();
        jQuery('.main_category_hover').attr('linked','no');
        jQuery('.sub_category_content').hide();
        jQuery(this).attr('linked','yes');
        jQuery(this).prev('ul').show();
   }).bind('mouseout',function(){
        
        if(jQuery(this).attr('linked')=='no'){
            jQuery(this).prev('ul').hide();
            jQuery(this).next().children('div:last-child').hide();
            jQuery(this).next().children('div:first-child').show();
        }
    });
    
   jQuery('.sub_category').bind('mouseover',function(){
        jQuery(this).children('div:last-child').show();
        jQuery(this).children('div:first-child').hide();
    }).bind('mouseout',function(){
       if(jQuery(this).attr('linked')=='no'){
        jQuery(this).children('div:last-child').hide();
        jQuery(this).children('div:first-child').show();
       }
    }).bind('click',function(){
        jQuery('.sub_category').attr('linked','no');
        jQuery('.sub_category').children('div:last-child').hide();
        jQuery('.sub_category').children('div:first-child').show();
        jQuery(this).attr('linked','yes');
        jQuery(this).children('div:last-child').show();
        jQuery(this).children('div:first-child').hide();

        var category_level_1ID=jQuery(this).attr('category_level_1ID');
        var category_level_2ID=jQuery(this).attr('category_level_2ID');
        if(jQuery('#'+category_level_2ID+'_div').html()){
            jQuery('#'+category_level_2ID+'_div > a:first').click();
        }
        else{
             jQuery("body").append('<div id="'+category_level_2ID+'_div" style="display:none;position:absolute;top:0px;left:0px;"></div>');
             jQuery('#loading').fadeIn('slow');
             jQuery.ajax({
             type: "GET",
             url: "index.php?",
             data:"portfolio=load&category_level_1ID="+category_level_1ID+"&category_level_2ID="+category_level_2ID,
             success: function(result){
                jQuery('#'+category_level_2ID+'_div').html(result);
               if(result){
                   //jQuery('#loading').fadeOut();
                   jQuery('#'+category_level_2ID+'_div > a:first').click();
                }
                else{
                    jQuery('#loading').html('<table width="100%" height="100%" cellpadding="0" cellspacing="0" style="background:#ffffff">\n\
                                                <tr><td valign="middle" align="center">\n\
                                                    <a style="font-size:16px;font-weight:normal" href="#" title="click to close">No images found for this Art.<br>Click to go back.</a> \n\
                                                </td></tr>\n\
                                               </table>');

                    jQuery('#loading').find('a').bind('click',function(){
                    jQuery('#loading').fadeOut('slow');
                    jQuery('#loading').html('');
                    });
                }
                    
             },
             error: function(){
                    jQuery('#loading').html('<table width="100%" height="100%" cellpadding="0" cellspacing="0" style="background:#ffffff">\n\
                                                <tr><td valign="middle" align="center">\n\
                                                    <a style="font-size:16px;font-weight:normal" href="#" title="click to close">Error in loading.<br>Click to go back.</a> \n\
                                                </td></tr>\n\
                                               </table>');

                    jQuery('#loading').find('a').bind('click',function(){
                    jQuery('#loading').fadeOut('slow');
                    jQuery('#loading').html('');
                    });
             }
            });
            
        }
    });
    /*set the heights based  on resize  */
    jQuery(window).resize();
})

/*=================================================================================*/
/*scrolling function*/
/*=================================================================================*/
jQuery(function( $ ){
    //Easing equation for panel
    jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
        return -c * ((t=t/d-1)*t*t*t - 1) + b;
    };
    var target = $('#content').get(0);//the scrolled div
        target.scrollLeft = target.scrollTop = 0;

    $.localScroll.hash({
        target: target, //could be a selector or a jQuery object too.
        axis:'xy',//the default is 'y'
        queue:true,
        duration:1800,
        easing:'easeOutQuart',
        hash:false,
        onBefore:function( e, anchor, $target ){
           menu_click(anchor.id+'_menu');
           jQuery("#validation_msg").slideUp();
           if(anchor.id.match('omar')){
               if(jQuery("#omar").css('visibility')=='hidden'){
                    jQuery('#omar').css({'visibility':'visible'})
                }
           }
        }
    });
    var $last = $([]);//save the last link
    $.localScroll({
        target: target, //could be a selector or a jQuery object too.
        axis:'xy',//the default is 'y'
        queue:true,
        duration:1800,
        easing:'easeOutQuart',
        hash:false,
        onBefore:function( e, anchor, $target ){
           menu_click(anchor.id+'_menu');
           jQuery("#validation_msg").slideUp();
        }
    });
});
