﻿(function($) {
	var isIE=function(v){return typeof v=='undefined' && $.browser.msie?true:(parseInt($.browser.version,10) == v? true: false);};
	var rbDIV='<div class=rbC1 /><div class=rbC2 /><div class=rbC3 /><div class=rbC4 /><div class=rbS1 /><div class=rbS2 /><div class=rbS3 /><div class=rbS4 /><div class=rbClose>X</div><div class=rbContent/>';
	var css={
		  background: 'none',
		  color:'#fff',
		  padding: 0, 
		  border: 0,	  
		  cursor: 'auto',
		  width: 440,
		  left:'50%',
		  top:80
	};
				
$.fn.blockUp=function(options){
	$(this).bind('click',function(e){
		e.preventDefault();
		var message=$.ajax({ type: 'GET', url: $(this).attr('href'), async: false }).responseText;
		var o = $.extend({},{message:message},options||{});
		$.blockMsg(o);
	});
	return $(this);
}

$.blockMsg=function(options){
	
	$.blockUI.defaults.css=css;
	options=$.extend({},$.blockUI.defaults,options||{});
	var width=options.width||$.blockUI.defaults.css.width;
	$.blockUI.defaults.css.width=width;
	$.blockUI.defaults.css.marginLeft= -width/2;
	
	$.blockUI(options);
	//console.log(options);
	$('.blockMsg').prepend(rbDIV).find('div[class^=rb]').css('opacity',.6);
	$(".blockOverlay,.rbClose,.popClose").bind('click',$.unblockUI);
}

})(jQuery);

// cufon
Cufon.replace('#accordian .tab h5 span, #accordian .accordian h2, #logo h1');
Cufon.replace('#header a', {
    hover: true
});

$(function(){
	$('.tab').addClass('clearfix');
    accordian();
    cycle();
	cycleFuture();
	// numbering
	/*$('#cycle-gallery div.title').each(function(i,j){
		var text = $(this).text();
		$(this).text(i + 1 + '. ' + text);
	})*/
	
    if ($.browser.msie && parseFloat($.browser.version) < 7) {
        $('.tab', '#accordian:not(".disabled")').hover(function(){
			$(this).addClass('rollover');
        }, function(){
			$(this).removeClass('rollover');
        });
    }
	
	$('.popup').blockUp({width:620});
	$('.popup2').blockUp({width:400});
	$('.map').blockUp({width:890});
	
	$('form').live('submit',function(){
		jQuery(this).validate();
		jQuery("input[name='first_name']", this).rules("add", {
		 required: true,
		 messages: {
		   required: ""
		 }
		});
		jQuery("input[name='surname']", this).rules("add", {
		 required: true,
		 messages: {
		   required: ""
		 }
		});
		jQuery("input[name='email']", this).rules("add", {
		 required: true,
		 email: true,
		 messages: {
		   required: "",
		   email: ""
		 }
		});
		jQuery(this).valid();

		var action = jQuery(this).attr("action");

			if(jQuery(this).valid()){
				var fields = jQuery(this).serialize();
				 jQuery.ajax({
				   type: "POST",
				   url: "email.php",
				   data: fields
				 });
				name = jQuery(this).find("input[name='first_name']").val();
				
			} else return false;

		//block.width=400;
		$.blockMsg({message:'<h5 align=center>Thank you '+name+'!</h5>'});
		return false;
	});

    if ($.browser.msie && parseFloat($.browser.version) < 7) {
        DD_belatedPNG.fix('#logo, #accordian .accordian .white_trans, .cycle-slide');
    }
	$('#lang').hover(function(){
		$(this).find('b').hide().end().find('span').fadeIn();
	},function(){
		var b = $(this).find('b'); 
		$(this).find('span').fadeOut(400, function(){b.show();});
	});

	var hash = parseInt(window.location.hash.replace(/#/,''));
	if(hash > 0){
		$('#accordian .tab').eq(hash-1).click();
	}
	
	
	$('#latest_projects').cycle({
        fx: 'scrollHorz',
        next: "#nxt",
        prev: "#prevs",
		after: function(curr, next, opts){
            var total = opts.slideCount;
            var current = opts.currSlide;
            var page = current + 1;
            $('#paging').text('Page ' + page + ' of ' + total);
        },
        cleartype: 1,
        speed: 2000,
        timeout: 0
    });
});
accordian = function(klass){
    $('.tab', '#accordian:not(".disabled")').live('click', function(){
        var self = $(this);
        var t = 400;
        //if ($.browser.msie && parseFloat($.browser.version) < 8) 
            //t = 0;
        
        if (self.hasClass('active')) {
            self.removeClass('active').next().stop().slideUp(t);
        }
        else {
            self.addClass('active').next().stop().animate({height:'toggle', opacity:'toggle'}, t)
			.end().siblings('.tab').removeClass('active').next().stop().slideUp(t);
        }
    });
    
}
cycle = function(){
	$cycle=$("#cycle-gallery");
	if(!$cycle.length) return false;
    $cycle.cycle({
        fx: 'scrollHorz',
        next: "#cycle #next",
        prev: "#cycle #prev",
        after: function(curr, next, opts){
            var total = opts.slideCount;
            var current = opts.currSlide;
            var page = current + 1;
            $('#cycle #page').text('Page ' + page + ' of ' + total);
        },
        cleartype: 1,
        speed: 2000,
        timeout: 0
    }).hover(function(){
        $(this).cycle('pause')
    }, function(){
        $(this).cycle('resume')
    });
}

cycleFuture = function(){
	$cycle=$("#cycle-gallery-future");
	if(!$cycle.length) return false;
    $cycle.cycle({
        fx: 'scrollHorz',
        next: "#futurenext",
        prev: "#futureprev",
        after: function(curr, next, opts){
            var total = opts.slideCount;
            var current = opts.currSlide;
            var page = current + 1;
            $('#page-future').text('Page ' + page + ' of ' + total);
        },
        cleartype: 1,
        speed: 2000,
        timeout: 0
    }).hover(function(){
        $(this).cycle('pause')
    }, function(){
        $(this).cycle('resume')
    });
}


