function init(targets){
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-673746-1']);
  _gaq.push(['_trackPageview']);


  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
	$('.validate').find('img').hover(function(){$(this).attr('src','imgs/subscribe-hover.jpg');},
                                         function(){$(this).attr('src','imgs/subscribe-normal.jpg');}
                                        );
	$('.validate').find('img').click(function(){return Mkto.formSubmit(document.getElementById('subscribeForm'));});
	$('.validate').find('input:text').focusin(function(){
    	if($(this).val() == $(this).attr('default')) {
			$(this).val('');
        }
	});
	$('.validate').find('input:text').focusout(function(){
 		if($(this).val().split(' ').join('') == '' ){
			$(this).val($(this).attr('default'));
		}
	});
	
	$(".callyou").colorbox({width:"650px", height:"270px", iframe:true, href: "http://dial.clicktodial.com.au/dialnow.php?a=1ly1mme73w&b=58qzlrsxb1"});
	
	for(var i=0; i < targets.length; i++){
		activeCurrentPage(targets[i]);	
	}
}

function flashBun(){
	$('div.flash').css({ display: "none", left: "auto" });
	
	$("a.look").toggle(function(){
		$(document)
			.find('div.flash')
			.stop(true, true)
			.slideDown('fast');
                $(this).addClass('close').attr('title','Close');
			}, function() {
		$(document)
			.find('div.flash')
			.stop(true, true)
			.slideUp('fast');
                $(this).removeClass('close').attr('title','Take A Look');
	});
	
	jQuery('#mycarousel').jcarousel({
                                scroll: 3,
    	                        auto: 5,
                                animation: 1500,
                                wrap: 'circular',
                                itemVisibleInCallback: {
                                    onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation
                                },
                                itemVisibleOutCallback: {
                                    onBeforeAnimation: mycarousel_itemVisibleOutCallbackBeforeAnimation
                                }
  });
}
function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
    jQuery('img', item).fadeIn(2800);
};
function mycarousel_itemVisibleOutCallbackBeforeAnimation(carousel, item, idx, state) {
    jQuery('img', item).fadeOut(1300);
};
function activeCurrentPage(target){
	$('.'+target).find('a').removeClass().addClass(target+'Cur');
}
function showCases(target){
	var positions = {'aapt':'20px','bms':'160px','localist':'310px','hilife':'460px','tony':'600px','teleco':'780px'};
	$('.casestudy').hide();
	$('.aapt').show();
	$($(target).find('a')).click(function (){
            $('.white_block').animate({ left: positions[$(this).parent().attr('id')]}, 500 );
            $('.casestudy').hide();
            $('.' + $(this).parent().attr('id')).fadeIn(700);
        });
}
function get_rss_feed(){
    $.ajax({url: "http://www.ipscape.com.au/blog/?feed=customfeed",
        type: "GET",
	success: function(data){
            var count = 0;
            var entry_num_limite = 4;
            var entry_len_max = 66;
            var i = 0;
            var title = '';
            var link = '';
	    var feeds = $(data).find('item');
            var feeds_length = $(feeds).length;
            for(i; i < feeds_length; i++){
                title = $(feeds[i]).find('title').text();
                if(title.length > entry_len_max){title = title.substr(0,entry_len_max)+'...';}
                link = $(feeds[i]).find('link').text();
                $('div#rss_feeds').append('<span style=\'display:block;\'><a href=\''+link+'\' >'+title+'</a></span>');
                count ++;
                if(count >= entry_num_limite){break;}
            }
       }
    });	
}

function fieldValidate(field) {
  /* call Mkto.setError(field, message) and return false to mark a field value invalid */
  /* return 'skip' to bypass the built-in validations */
  return true;
}
function getRequiredFieldMessage(domElement, label) {
  return "This field is required";
}
function getTelephoneInvalidMessage(domElement, label) {
  return "Please enter a valid telephone number";
}
function getEmailInvalidMessage(domElement, label) {
  return "Please enter a valid email address";
}
function formReset(elt) {
  return Mkto.formReset(elt);
}

$(document).ready(function(){ 
    $(':input').blur(function() { 
        $(this).val($(this).val().replace(/<[^>]*>/g,'')); 
    }); 
    $('textarea').blur(function() { 
        $(this).val($(this).val().replace(/<[^>]*>/g,'')); 
    }); 
});
