/*
    By Jason Palmer
    http://www.jason-palmer.com/2008/08/jquery-plugin-form-field-default-value/
*/
jQuery.fn.DefaultValue = function(text){

    return this.each(function(){
        //Make sure we're dealing with text-based form fields
        if(this.type != 'text' && this.type != 'password' && this.type != 'textarea') {
            return;
        }
        
        //Store field reference
        var fld_current=this;
        
        //Set value initially if none are specified
        if(this.value === '') {
            this.value=text;
        } else {
            //Other value exists - ignore
            return;
        }
        
        //Remove values on focus
        $(this).focus(function() {
            if(this.value === text || this.value === '' ) {
                this.value='';
            }
        });
        
        //Place values back on blur
        $(this).blur(function() {
            if(this.value === text || this.value === '') {
                this.value=text;
            }
        });
        
        //Capture parent form submission
        //Remove field values that are still default
        $(this).parents("form").each(function() {
            //Bind parent form submit
            $(this).submit(function() {
                if(fld_current.value==text) {
                    fld_current.value='';
                }
            });
        });
    });
};


jQuery(function(){
    $("#main-menu ul>li").hover(
        function() {
            var el = $("div.bigmenu-wrapper", this);
            $(el).show();
            $(el).css( 'top', $("#content-wrapper").offset().top );
            $(el).css( 'left', $("#content-wrapper").offset().left );   
        },
        function() {
            var el = $("div.bigmenu-wrapper", this);
            $(el).hide();
        }
    );
    
    
    /* Tabs */
    $(".tab").hide();
    
    $("#tabs .nav a").click(function(){
        $("#tabs .nav li").removeClass("current");
        $(".tab").hide();
        $("#tab-" + $(this).attr("href").split('#')[1] ).show();
        $(this).parents("li").addClass("current");
        return false; 
    });
    
    
    var currentfile = document.location.toString();
    if (currentfile.match('#')) { 
        // the URL contains an anchor
        // click the navigation item corresponding to the anchor
        var myAnchor = '#' + currentfile.split('#')[1];
        $('#tabs .nav a[href="' + myAnchor + '"]').click();
    } else {
        // click the first navigation item
        $('#tabs .nav a:first').click();
    }
    
    
    /* Fix click on anchor in menu to reload page */
    $(".bigmenu a").click(function(){
        var current_path = document.location.pathname;
        var current_link = $(this).attr("href"); 
        //alert(current_path);
        //alert(current_link);
        if (current_link.match('#')) { 
            // the URL contains an anchor
            // click the navigation item corresponding to the anchor
            if (current_path == current_link.split('#')[0] ) {
                var myAnchor = '#' + current_link.split('#')[1];
                $('#tabs .nav a[href="' + myAnchor + '"]').click();
                $("div.bigmenu-wrapper").hide();
                //return false;
            }
        }
        return true;
        
    });
    
    //alert( window.location.pathname + window.location.search + window.location.hash );
    /* Stick menu */
    // Pour garder l'état du menu ouvert selon l'url cliqué
    // Si le lien est dans un bigmenu, il faut allumer le a du li parent
    $('#main-menu').find('a[href=' + window.location.pathname + window.location.search + window.location.hash + ']').addClass('selected').parents('.bigmenu-wrapper').parent().find('a:first').addClass('selected');
    //var el = $('#main-menu').find('a[href=' + window.location.pathname + window.location.search + window.location.hash + ']').parents('.bigmenu-wrapper').parent().find('a:first').addClass('selected');
    
    //$('#main-menu').find('a[href=' + window.location.pathname + window.location.search + ']').addClass('selected');
    /*
    var pathArray = window.location.pathname.split( '/' );
    var newPath = "";
    
    for (i = 0; i < pathArray.length; i++) {
        newPath += pathArray[i] + "/";
        $('#menu, .sousmenu').find('a[@href=' + newPath + ']').addClass('selected');
    }
    */
    
    
    
    /* Add icon to link */
    $('a[href$=".doc"]').css({
        paddingRight: '18px',
        background: 'transparent url("/imports/sys/fileinfo/icone_doc.gif") no-repeat center right'
    });
    $('a[href$=pdf]').css({
        paddingRight: '18px',
        paddingTop: '1px',
        paddingBottom: '1px',
        background: 'transparent url("/imports/sys/fileinfo/icone_pdf.gif") no-repeat center right'
    });
    $('a[href$=jpg], a[href$=JPG]').not(".no-icon").css({
        paddingRight: '18px',
        background: 'transparent url("/imports/sys/fileinfo/icone_img.gif") no-repeat center right'
    });
    // External link
    $('a[target=_blank]').filter("a[href^=http]").css({
        paddingRight: '12px',
        background: 'transparent url("/imports/images/icons/external_link.png") no-repeat center right'
    });
    
    
    
    
    
    $(".show-more").click(function(){
        $(this).hide();
        $(this).next().slideDown();
        return false;
    });
    
    //$(".lightbox-wrapper a").filter(":not(:first)").hide();
    $(".lightbox-wrapper").each(function(){
        $(this).find("a:not(:first)").hide();
    });
    
    // Parse lightbix link
    /*$('.lightbox-wrapper a').lightBox({
	    imageLoading:			'/imports/jscript/jquery/lightbox/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
		imageBtnPrev:			'/imports/jscript/jquery/lightbox/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
		imageBtnNext:			'/imports/jscript/jquery/lightbox/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
		imageBtnClose:			'/imports/jscript/jquery/lightbox/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
		imageBlank:				'/imports/jscript/jquery/lightbox/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)
	    txtOf:'de'
    });*/
    $('.lightbox-wrapper').each(function(){
        $("a", this).lightBox({
            imageLoading:			'/imports/jscript/jquery/lightbox/lightbox-ico-loading.gif',
            imageBtnPrev:			'/imports/jscript/jquery/lightbox/lightbox-btn-prev.gif',
            imageBtnNext:			'/imports/jscript/jquery/lightbox/lightbox-btn-next.gif',
            imageBtnClose:			'/imports/jscript/jquery/lightbox/lightbox-btn-close.gif',
            imageBlank:				'/imports/jscript/jquery/lightbox/lightbox-blank.gif',
            txtOf:_phtech_message.de
        });
    });
    
    
    
      // Parse lightbix link
    $('.lightbox').lightBox({
	    imageLoading:			'/imports/jscript/jquery/lightbox/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
		imageBtnPrev:			'/imports/jscript/jquery/lightbox/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
		imageBtnNext:			'/imports/jscript/jquery/lightbox/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
		imageBtnClose:			'/imports/jscript/jquery/lightbox/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
		imageBlank:				'/imports/jscript/jquery/lightbox/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)
	    txtOf:_phtech_message.de
    });
    
    
    
    
    
    
    
    
});
