$(document).ready(function() {
    
    //Some global vars to make edits nice and easy
    Femmes.contacts = $('.location-select');
    Femmes.active = 'active';
    Femmes.countryList = 'menu-titulo-lista';
    Femmes.officeInfo = 'sub-titulo-lista';
    Femmes.contactInfo = 'sub-texto-lista';
    //window.addEventListener("orientationchange", Femmes.hideURLBar, false);
    //Check device and deliver appropriate content
   
    Femmes.regionClick();
    Femmes.countryClick();
    Femmes.MediaQuerySWF('#flashContent', 'main_pt.swf', 'flashMovie');

    
});

//Declare Femmes namespce
var Femmes = {};

//Click event for the region list items, calls Femmes.toggle
Femmes.regionClick = function() {
    Femmes.contacts.children('li').click(function() {
        $(this).find('.' + Femmes.countryList).children('li').removeClass('active');
        $('.' + Femmes.officeInfo).stop(true, true).slideUp(300);
        Femmes.toggle(this, '.' + Femmes.countryList);
    });
};

//Click event for the country list items, calls Femmes.toggle
Femmes.countryClick = function(){
    $('.'+Femmes.countryList).children('li').click(function(e){
        e.stopImmediatePropagation();
        Femmes.toggle(this, '.'+Femmes.officeInfo);
    });
};

//This function handles the toggle event for the region and countries click events
Femmes.toggle = function(element, list){
    $(element).siblings().find(list).stop(true, true).slideUp(300);
    $(element).siblings().removeClass('active');
    $(element).find(list).is(':visible') ? $(element).removeClass('active') : $(element).addClass('active');
    $(element).find(list).stop(true, true).slideToggle(300);
};


//This loads the swfobject
Femmes.LoadSWF = function (swf, elementId, width, height, version) {
    var flashobject = swf;
    var expressinstall = 'expressInstall.swf';
	var flashvars = {};
	var params = {
	    quality: "high",
	    play: "true",
	    loop: "false",
	    scale: "scale",
	    wmode: "transparent",
	    devicefont: "false",
	    bgcolor: "#ffffff",
	    menu: "true",
	    allowfullscreen: "true",
	    allowscriptaccess: "sameDomain"
	};
	var attributes = {
	    id: "main_pt",
	    name: "main_pt"
	};

    swfobject.embedSWF(flashobject, elementId, width, height, version, expressinstall, null, params, attributes);
	swffit.fit("main_pt", "100%", "100%");
};

//Hides the SWF from mobile browsers that run Flash (android) -- used in conjunction with css media query
//Still needs to be implemented!
Femmes.MediaQuerySWF = function (element, swf, movieContain) {
	var display = $(element).css('display');
	if (display == 'none') {
		$(element).css('display', 'block');
		$(element).css('width', '100%');
		$(element).css('height', '100%');
	} else if (document.documentElement.clientWidth <= 480) {
		$(element).css('display', 'block');
		$(element).css('width', '100%');
		$(element).css('height', '100%');
	} else {
		Femmes.LoadSWF(swf, movieContain, '100%', '100%', '10.0.0'); // use this to load swf instead of whatever's currently being used?
	}
};

// Hide the navigation bar
Femmes.hideURLBar = function() {
	window.scrollTo(0, 1);
};

// Legacy code from common.js
var openWin;
function newWin(popUrl){
		var openWin = window.open(popUrl,'newPopup','menubar=no,scrollbars=yes,resizable=no,width=560,height=444');
		openWin.focus();
}
