$("document").ready(function() {
	// HOMEPAGE SLIDESHOW
	$("div.banner-wrap")
	.after('<div class="like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwearflags.com&amp;layout=standard&amp;show_faces=false&amp;width=260&amp;action=like&amp;colorscheme=light&amp;height=30" scrolling="no" frameborder="0" style="border:none;overflow:hidden; width:260px;height:30px;" allowTransparency="true"></iframe></div><div class="banner-control">')
	.cycle({
	    fx:     'fade',
	    timeout: 6000,
	    pager:  '.banner-control',
	    cleartype: true,
	    cleartypeNoBg: true
	});
	// CONTENT SLIDESHOW (content slideshow on the home page)
	$(function() {
		var contentWrapper = $('.main > .tab');
		contentWrapper.hide().filter(':first').show();
		$('.main ul.tabs-nav li a').click(function () {
		    if (this.className.indexOf('current') == -1){
		    	contentWrapper.hide();
		    	contentWrapper.filter(this.hash).fadeIn(500);
		    	$('.main ul.tabs-nav li a').removeClass('current');
		    	$(this).addClass('current');
		    }
		    return false;
		});
	});
	
	$('#list_cities').hide();
	$('a#toggle_cities').toggle( 
		function() { $('#list_cities').slideDown(); $(this).html('Hide'); },
		function() { $('#list_cities').slideUp();   $(this).html('Show'); } 
	);
	$('#list_categories').hide();
	$('a#toggle_categories').toggle( 
		function() { $('#list_categories').slideDown(); $(this).html('Hide'); },
		function() { $('#list_categories').slideUp();   $(this).html('Show'); } 
	);
	$('#show-all').hide();
	$('a#toggle_featured').toggle( 
		function() { $('#show-featured').hide(); $('#show-all').show(); $(this).html('Show Featured'); },
		function() { $('#show-all').hide(); $('#show-featured').show();   $(this).html('Show All'); } 
	);
});
// Image loader
function imageLoader() {
    $('.loader').each(function () {
        var loader = $(this);
        var pathToImage = loader.attr('title');
        var img = new Image();
        $(img).css("opacity", "0.0").load(function () {
            loader.append(this).removeAttr('title');
            $(this).css("margin", "0px").css("opacity", "0.0").animate({
                opacity: 1.0
            },400, function () {
                loader.css({ "background-image": "none", "background-color": "transparent" });
            });
        }).attr('src', pathToImage);
    });
}
$("document").ready(function() {
    imageLoader();
});
function clearfield(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
function fillfield(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}
function modal() {
	$("#modal").modal({
		opacity:32,
		overlayCss: {backgroundColor:"#000"},
		overlayClose:true, 
		position:['40%','30%']
	});
    return false;
}
