﻿/*--------Cufon Font--------*/

Cufon.replace("h1, .home-heading, .heading-duplicate, .home-heading2, .featured-title, .page-parent, .overview-title, .project-title,.supplier-title, .form-heading", { fontFamily: 'DIN-Regular' });


/*--------Homepage Fader--------*/

$(document).ready(function() { 
$('#cycle-container')
.before('<div id="cycle-button"><ul>') 
.cycle({ 
    fx:     'fade', 
    speed:  '800', 
    timeout: 4000, 
    pager:  '#cycle-button ul',
	pagerAnchorBuilder: function(idx, slide) {
		var anchor = '';
		anchor = '<li><a href="#" id="btn-cycle-' + (idx + 1) + '">' + (idx + 1) + '</a></li>';
		return anchor;
	}
});
});

/*--------Category Drop-Down--------*/

$(document).ready(function() { 
         
    $("#util-cat a").tooltip({ 
		effect: 'slide', 
		slideOffset: 0,
		offset: [190,-17],
		fadeInSpeed: 1000,
		fadeOutSpeed: 1000,
		relative: true
	});  
});

/*--------Grey Scale Fade--------*/

$("#gallery-overview-list .gallery-thumb")
	.filter(":nth-child(1)")
	.find("a.thumb").prepend('<span class="image-thumb"><img src="/images/overview/gallery-overview/btn-gallery-commercial.jpg" /></span>');
	
$("#gallery-overview-list .gallery-thumb")
	.filter(":nth-child(2)")
	.find("a.thumb").prepend('<span class="image-thumb"><img src="/images/overview/gallery-overview/btn-gallery-institutional.jpg" /></span>');

$("#gallery-overview-list .gallery-thumb")
	.filter(":nth-child(3)")
	.find("a.thumb").prepend('<span class="image-thumb"><img src="/images/overview/gallery-overview/btn-gallery-residential.jpg" /></span>');

$(document).ready(function() {
	
	$("#gallery-overview-list .gallery-thumb").hover(function() { 
		
		var thumbOver = $(this).find("img").attr("src"); 
		
		$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		$(this).find(".image-thumb").stop().fadeTo('normal', 0 , function() {
			$(this).hide() 
		}); 
		
	} , function() { 
		$(this).find(".image-thumb").stop().fadeTo('normal', 1).show();
	});

});

/*$(document).ready(function() {
	
	$("#gallery-overview-list .gallery-thumb").hover(function() { 
		
		var thumbOver = $(this).find("img").attr("src"); 
		
		$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() 
		}); 
		
	} , function() { 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});

});
*/
/*--------Gallery Overview - 3rd List--------*/

$(document).ready(function() {
	$("#overview-list .overview-list-elements")
		.filter(":nth-child(3),:nth-child(6),:nth-child(9),:nth-child(12)")
	.addClass("third-overview");
}); 

/*--------Gallery Listing Overview - 4th List--------*/

$(document).ready(function() {
	$("#gallery-listing .gallery-listing-overview")
		.filter(":nth-child(4),:nth-child(8),:nth-child(12),:nth-child(16)")
	.addClass("fourth-overview");
}); 

$(document).ready(function() {
	$(".gallery-results:odd").css("padding-right", "0px");
	$("#cta li:last").css("margin-right", "0px");
}); 	

/*--------Gallery  Overview - Last element--------*/

$(document).ready(function() {
	$(".gallery-thumb:last").addClass("last");;
}); 

/*--------Gallery Tooltip--------*/

$(document).ready(function() { 
	$("#gallery-image-featured a.icon1").tooltip({
		effect: 'slide',
		tip: '#comment-box1',
		offset: [0,0],
		relative: true

	}); 
	$("#gallery-image-featured a.icon2").tooltip({
		effect: 'slide',
		tip: '#comment-box2',
		offset: [0,0],
		relative: true

	}); 
	$("#gallery-image-featured a.icon3").tooltip({
		effect: 'slide',
		tip: '#comment-box3',
		offset: [0,0],
		relative: true

	}); 
});

/*--------Gallery Tooltip--------*/

$(document).ready(function(){
    $("#project-thumb-container a").hover(function(){
        var imgHref = $(this).attr('href');  //get the src of the thumbnail
        $("#project-thumb-container a").removeClass("selected");  //remove .selected class from all other links
        $(this).addClass("selected");  //add .selected class to current link
        $(".big").stop();
        $(".big").stop().fadeTo(0, 0, function() {  //fade image out
            $('.big').attr('src',imgHref);  //give new image a src attribute
        }).fadeTo("fast", 1);  //fade the image in
		
		if($(this).parent().attr('id') == "tooltip-parent") {
			$('#gallery-image-featured a').show();
		} else {
			$('#gallery-image-featured a').hide();			
		}		
		
        },function(){    //for onmouseout not used here		
    });
});


$("#project-thumb-container a").click(function(){  
	return false;  
});  

/*--------Fake file inputs--------*/

$(document).ready(function() {
	$('input[type=file]').each(function(){
		var uploadbuttonlabeltext = $(this).attr('title'); //get title attribut for languagesettings
		if(uploadbuttonlabeltext == ''){
			var uploadbuttonlabeltext = 'Browse...';
		}
		 
		var uploadbutton = '<input type="button" class="form-btn-browse" value="'+uploadbuttonlabeltext+'" />';
		$(this).wrap('<div class="fileinputs"></div>');
		$(this).addClass('file').css('opacity', 0); //set to invisible
		$(this).parent().append($('<div class="fakefile" />').append($('<input type="text" class="form-input-field" disabled="disabled" />').attr('id',$(this).attr('id')+'__fake')).append(uploadbutton));
		$(this).bind('change', function() {
			$('#'+$(this).attr('id')+'__fake').val($(this).val());;
		});
		$(this).bind('mouseout', function() {
			$('#'+$(this).attr('id')+'__fake').val($(this).val());;
		});
	});
});

/*$("#gallery-image img").wrap("<table><tr><td></td></tr></table>");*/

$("#gallery-image img.big").wrap("<table><tr><td></td></tr></table>");



/*--------Character Counter for inputs and text areas--------*/
$(document).ready(function() {
    $('.word_count').each(function() {
        // get current number of characters  
        var length = $(this).val().length;
        // get current number of words  
        //var length = $(this).val().split(/\b[\s,\.-:;]*/).length;
        // update characters
        if (length > 0)
            $('.counter_view').html(length + ' characters');
        if (length > 850)
            $('.counter_view').attr("style", "color:red");
        else
            $('.counter_view').attr("style", "");
        // bind on key up event  
        $(this).keyup(function() {
            // get new length of characters
            var new_length = $(this).val().length;
            // get new length of words  
            //var new_length = $(this).val().split(/\b[\s,\.-:;]*/).length;
            // update
            //            if (new_length > 10) {
            //                $(this).val($(this).val().substring(0, 10));
            //            }
            //            else
            $('.counter_view').html(new_length + ' characters');
            if (new_length > 850) {
                $('.counter_view').attr("style", "color:red");
                $('.count_error_msg').attr("style", "color:red; visibility:visible");
            }
            else {
                $('.counter_view').attr("style", "");
                $('.count_error_msg').attr("style", "visibility:hidden");
            }

            $('input.counter_store').val(new_length);
        });
    });
});