// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// jQuery preload images
jQuery.preloadImages = function() {
	for(var i=0; i<arguments.length; i++) {
		$("<img>").attr("src", arguments[i]);
	}
}

$(document).ready(function(){
	// alert('jQuery loves you!');
	
	// 10 Days Giveaways Terms and Conditions

	
	$("#terms_link").click(function(){
		$("#form").hide();
		$("#terms").show();
		return false;
	});

	$("#form_link").click(function(){
		$("#terms").hide();
		$("#form").show();
		return false;
	});

	// support answer toggle
	$(".question").click(function(){
		$(".answer").hide();
		$(this).siblings(".answer").show();
		return false;
	});
	
	// support contact dropdown
	$("select#support_contact").change( function() {
		if (url = $(this).val()) {
			window.location = url;
		}
	});
	
	$(function() {
	  $('form a.add_child').click(function() {
	
	    var assoc   = $(this).attr('data-association');
	    var content = $('#' + assoc + '_fields_template').html();
	    var regexp  = new RegExp('new_' + assoc, 'g');
	    var new_id  = new Date().getTime();

	    $(this).parent().before(content.replace(regexp, new_id));    
	    return false;
	  });

	  $('a.remove_child').live('click', function() {
		
	    var hidden_field = $(this).prev('input[type=hidden]')[0];
	    if(hidden_field) {
	      hidden_field.value = '1';
	    }
	    $(this).parents('.fields').hide();
	    return false;
	  });
	});
	
	

});

/* REGION SELECTOR */
Shadowbox.loadSkin('classic', '/shadowbox/skin');
$(document).ready(function(){
	Shadowbox.init({
        overlayColor: '#000',
        overlayOpacity: 0.9
  });
  $('#changeregion').click(function(e){
    e.preventDefault();
    s = Shadowbox.open({
      content: '/settings',
      width: '180px',
      height: '250px',
      player: 'xhr',
      title: 'Select a region:'
    });
  });
  
  if(region == '') $('#changeregion').triggerHandler('click');
});
