$(function() {

    /* --------------------------------------- */
    /* OPEN LINK TO BLANK WITH EXTERNAL REL */
    /* --------------------------------------- */
    $("a[rel*='external']").click(function() {
        this.target = "_blank";
    });

    //var newWidth = 500; // the maximum goal width, in pixels
    //$(".info-panel p", ".test1").textTruncate(newWidth, '&nbsp;&nbsp;<a href="#">...more</a>');
   
   /* if ($('.cnt-panel .cnt-i .wrap li').size()) {
        $('.cnt-panel .cnt-i .wrap li:last-child p:last-child').css({ 'padding': '0 0 0 25px;' });
    } else {
        $('.cnt-panel .cnt-i .wrap p:last-child').css({ 'padding': 0 });
    }*/
	$('.cnt-panel .cnt-i .wrap p:first').css({ 'margin-top': 0 });
    $('.cnt-panel .cnt-i .wrap p:last-child').css({ 'padding-bottom': 0 });
    
	var ie = $.browser.msie && $.browser.version < 8 ? true : false

    /* --------------------------------------- */
    /* Hover on Top Info */
    /* --------------------------------------- */
    $(".header .info-panel p.longtxt").css({ 'position': 'absolute', 'top': '0px' });
    var infoPanelMaxHeight = $(".header .info-panel p.longtxt").height();
    $(".header .info-panel p.longtxt").hide();

    var normalTextLength = $(".header .info-panel p.longtxt").text().length;
    var truncatedText = $(".header .info-panel p.longtxt").text().substring(0, 243);

    if (normalTextLength > truncatedText.length) {

        $(".header .info-panel").prepend("<p class='truncated'>" + truncatedText + "...<strong>more</strong></p>");
        var infoPanelMinHeight = $(".header .info-panel p.truncated").height();

        $(".header .info-panel").mouseenter(function() {
            $(".header .info-panel p.truncated").stop().animate({ 'height': infoPanelMaxHeight + 10 + "px", 'opacity': 0 }, 200, function() {
               $(".header .info-panel p.longtxt").slideDown('fast');			   
				if (ie) {
				   $(".header .info-panel ins.pan").css({
						bottom:  0
					})
			   }
            });
        });
        $(".header .info-panel").mouseleave(function() {
            $(".header .info-panel p.longtxt").slideUp('fast', function() {
               $(".header .info-panel p.truncated").stop().animate({ 'height': infoPanelMinHeight + "px", 'opacity': '' }, 200);
			   if (ie) {
				   $(".header .info-panel ins.pan").css({
						bottom:  (infoPanelMaxHeight - infoPanelMinHeight + 10)  + 'px'
					})
			   }
            });
        });
    } else {
        $(".header .info-panel p.longtxt").attr('style', '');
    }

    /* --------------------------------------- */
    /* Hover on Bottom Info */
    /* --------------------------------------- */
    $(".footer .info-panel p.longtxt").css({ 'position': 'absolute', 'top': '0px' });
    var infoPanelMaxHeight2 = $(".footer .info-panel p.longtxt").height();
    $(".footer .info-panel p.longtxt").hide();

    var normalTextLength2 = $(".footer .info-panel p.longtxt").text().length;
    var truncatedText2 = $(".footer .info-panel p.longtxt").text().substring(0, 243);

    if (normalTextLength2 > truncatedText2.length) {

        $(".footer .info-panel").prepend("<p class='truncated'>" + truncatedText2 + "...<strong>more</strong></p>");
        var infoPanelMinHeight2 = $(".footer .info-panel p.truncated").height();

        $(".footer .info-panel").mouseenter(function() {
            $(".footer .info-panel p.truncated").stop().animate({ 'height': infoPanelMaxHeight2 + "px", 'opacity': 0 }, 200, function() {
                $(".footer .info-panel p.longtxt").slideDown('fast');
            });
        });
        $(".footer .info-panel").mouseleave(function() {
            $(".footer .info-panel p.longtxt").slideUp('fast', function() {
                $(".footer .info-panel p.truncated").stop().animate({ 'height': infoPanelMinHeight2 + "px", 'opacity': '' }, 200);
            });

        });
    } else {
        $(".footer .info-panel p.longtxt").attr('style', '');
    }

    /* --------------------------------------- */
    /* Installation Panel */
    /* --------------------------------------- */
    if ($('.cnt-installation').length) {
        $('.cnt-gr-panel .cnt-gr-i .wrap ins.leaf').addClass('cnt-inst-leaf');
        $('.cnt-gr-panel > .cnt-gr-b').hide();

    } else {
        $('.cnt-gr-panel .cnt-gr-i .wrap ins.leaf').removeClass('cnt-inst-leaf');
        $('.cnt-gr-panel > .cnt-gr-b').show();
    }


    $('#gall_content').cycle({
        fx: 'scrollLeft',
        speed: 'normal',
        timeout: 0,
        pager: '#gall_frame',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#gall_frame li:eq(' + (idx) + ') a';
        }
    });

    /* --------------------------------------- */
    /* BROWSER DETECTION */
    /* --------------------------------------- */
    //A. Target Safari
    if ($.browser.safari) { }

    //B. Target anything above IE6
    if ($.browser.msie && $.browser.version > 6) { }

    //C. Target IE6 and below
    if ($.browser.msie && $.browser.version <= 6) { }

    //D. Target Firefox 2 and above
    if ($.browser.mozilla && $.browser.version >= "1.8") { }

});
