/*!
 * OuterHTML v1.0.0 (Release version)
 *
 * http://www.darlesson.com/
 *
 * Copyright 2010, Darlesson Oliveira
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * @requires jQuery v1.4.0 or above
 *
 * Reporting bugs, comments or suggestions: http://darlesson.com/contact/
 * Documentation and other jQuery plug-ins: http://darlesson.com/jquery/
 * Donations are welcome: http://darlesson.com/donate/
 */
 
// Examples and documentation at: http://darlesson.com/jquery/outerhtml/

// jQuery outerHTML
(function($){$.fn.extend({outerHTML:function(value){if(typeof value==="string"){var $this=$(this),$parent=$this.parent();var replaceElements=function(){var $img=$this.find("img");if($img.length>0){$img.remove();}
var element;$(value).map(function(){element=$(this);$this.replaceWith(element);})
return element;}
return replaceElements();}else{return $("<div />").append($(this).clone()).html();}}});})(jQuery);

jQuery.noConflict();

var conf = {
    over: menuIn,
    timeout: 300,
    out: menuOut
};

function menuIn(){
    jQuery(this).find('ul').fadeIn(500);
}
function menuOut(){
    jQuery(this).find('ul').fadeOut(500);
}

function pholder(elem, val, type) {  
    if(type==='click' && (elem.value === '' || elem.value === val)) {  
          elem.value = '';  
    } else if(type === 'blur' && (elem.value ==='' || elem.value === val)){  
        elem.value = val;  
    } else{
        return true;
    }
} 

function decrease(){
    var increaseValue = 150;
    var minLeft = 0;
    var left = parseInt(jQuery('.gallerietemp').css('left').split('px'));
    
 
        
        if(left < minLeft){
            
            jQuery('.gallerietemp').stop(true, true).animate({'left': left+increaseValue}, 250);
            if((left+increaseValue) >= minLeft){
               jQuery('.left').remove();
               jQuery('.right').remove();
               jQuery('.slideshow').append("<div class='right' onclick='increase()'></div>"); 
                
            }else{
                jQuery('.right').remove();
                jQuery('.left').remove();
                jQuery('.slideshow').append("<div class='left' onclick='decrease()'></div><div class='right' onclick='increase()'></div>");
                
            }
            
        }else{
            return;
        }
 }

var hideYoutube = {
   over: hideThis,
   timeout: 1000,
   out: showThis  
};


function hideThis(){
    if(flag==true){
        jQuery('.first iframe').hide();
        jQuery('.content-right.first').append('<img src="fileadmin/template/images/screenshot.jpg" class="screenshot"/>');
        flag = false;
    }
}

function showThis(){
    if(flag==false){
        jQuery('.first iframe').show(); 
        jQuery('.screenshot').remove();
        flag = true;
    }
    
}

function increase(){
    var increaseValue = 150;
    var j = jQuery('.gallerietemp').children().length;
    
    
    var maxLeft = (j - 4) * increaseValue;

    var left = parseInt(jQuery('.gallerietemp').css('left').split('px'));
    
    if(-left < maxLeft){

        jQuery('.gallerietemp').stop(true, true).animate({'left': left-increaseValue}, 250);
        if((left-increaseValue) <= -maxLeft){
           jQuery('.right').remove();
           jQuery('.left').remove();
            jQuery('.slideshow').append("<div class='left' onclick='decrease()'></div>"); 
        }else{
            jQuery('.right').remove();
            jQuery('.left').remove();
            jQuery('.slideshow').append("<div class='left' onclick='decrease()'></div><div class='right' onclick='increase()'></div>");
        }

    }else{
        
        return;
    }
}



jQuery(document).ready(function(){
flag = true;
jQuery('.container-right').find('img').each(function(){
   jQuery(this).wrap('<div class="sponsor" />');
});

jQuery('.slider').cycle({
        fx: 'fade',
        speed: 2500,
        timeout: 7000,
        pager: '#nav'
    });

jQuery('ul.menu').find('ul').each(function(){
    jQuery(this).hide();
})    
    
    jQuery('.csc-textpic-imagewrap').click(function(){
        hideThis();
    });
    
    jQuery('#overlay').click(function(){
       showThis(); 
    });
    
    jQuery('.content-right.first').click(function(){
       showThis(); 
    });
    
    jQuery('.slideshow').click(function(){
       hideThis(); 
    });
    jQuery('#lbLightbox').click(function(){
       showThis(); 
    });
    
    jQuery('ul.menu').hoverIntent(hideYoutube);
    
    jQuery('ul.menu li').hoverIntent(conf);
    jQuery('.gallerietemp').css('width', (jQuery('.gallerietemp').children().length * 150));
    if(jQuery('.gallerietemp').children().length >= 1){
        jQuery('.slideshow').append('<div class="right" onclick="increase()"></div>')
    }
});


