jq(document).ready(function(){

	FixedFooter();
	
	jq('.submenu li.level-1 > a ').live('click', function(){
		if (jq(this).siblings('ul').length) {
			jq('ul.submenu_show').removeClass('submenu_show').addClass('submenu_hidden');
			jq(this).next('ul.submenu_hidden').removeClass('submenu_hidden').addClass('submenu_show');
			jq('.submenu li.level-1 > a').removeClass('selected');
			jq(this).addClass('selected');
			return false;
		}
	})
	
	if (jq('#home_zone_link.not_authenticated').length) {
		jq('#home_zone_link.not_authenticated').click(function(){
			if (jq('#home_zone_login').width() > 0){
				jq('#home_zone_login').animate(
					{width:0},
					400,
					"easeInBack");
			} else {
				jq('#home_zone_login').animate(
					{width:406},
					400,
					"easeOutBack");
			}
			return false;
		});
	}
	
	if (jq('#home_slides .home_slides_container').children().length > 1) {
		jq('#home_slides').slides({
            play:4000,
            container:'home_slides_container',
            generatePagination: false,
            prev: 'home_slides_prev',
            next: 'home_slides_next'
        });
	}

	
	if (jq('div#colors').length) {
		jq('a.color_round').fancybox();
	}
	
	if (jq('div#retailers').length) {
		jq('#retailers_submit').click(function(){
			document.retailers_form.submit();
			return false;
		})
	}

	if (jq('div#employment').length) {
		jq('#employment_submit').click(function(){
			document.employment_form.submit();
			return false;
		})
	}

	if (jq('div#contact').length) {
		jq('#contact_submit').click(function(){
			document.contact_form.submit();
			return false;
		})
	}
	
	// Second carousel for projects. Checks if a carousel is active before activating it
	if (jq('.project_photos_selector .active_carousel').length) {
		jq(".project_photos_selector .active_carousel").jCarouselLite({
			btnNext: ".project_photos_selector_next",
			btnPrev: ".project_photos_selector_prev",
			visible: 6
		});
	}
	
	if (jq('#projects .projects_header').length) {
		jq('#id_client').change(function(){
			document.client_form.submit();
			return false;
		})

		jq('#id_collection').change(function(){
			document.collection_form.submit();
			return false;
		})
	}

	
})

function FixedFooter(){
	jq('#wrapper').height('');
	if(jq('body').height() <= jq(window).height()) {
		jq('#wrapper').height(jq(window).height());
		jq('#footer_wrapper').css('position', 'fixed').css('bottom',0)
	} else {
		jq('#wrapper').height('');
		jq('#footer_wrapper').css('position', 'static').css('bottom','')
	}
}

function FilterStates(retailers_url, state_val, country_val) {
	
	var stateList = jq('#id_state');
	stateList.attr('disabled', 'disabled');

	var countryList = jq('#id_country');
        if (country_val) {
            var country_id = country_val;
			jq('#id_country').val(country_id);
        } else {
            var country_id = jq('#id_country option:selected').val();
        }
	if (country_id > 0) {
                jq.ajax({
                    url: String(retailers_url) + 'states/' + country_id + '/',
                    success: function(data){
                        jq('#id_state').html(data);
                        
                        stateList.removeAttr("disabled");
                        if (state_val > 0) {
                                stateList.val(state_val);
                        }
                    }
                });
	}
	else {
		stateList.attr('disabled', 'disabled');
	}
}

function openPeel(){
	jq('#corner_small_content').width(800).height(800);
	jq('#corner_small').css('width','800px').css('height', '800px');
}

function closePeel(){
	jq('#corner_small_content').width(160).height(160);
	jq('#corner_small').css('width','160px').css('height', '160px');
}

function thisMovie(movieName) {
	if(document.embeds[movieName])
		return document.embeds[movieName];
	if(window.document[movieName])
		return window.document[movieName];
	if(window[movieName])
		return window[movieName];
	if(document[movieName])
		return document[movieName];
	return null;
}





