$(document).ready(function() {
    var locSplit = location.host.split('.');
    document.cookie = '__golive_lang='+locSplit[0]+';';  
    
    $.each($(".dropdownjs dd ul li"),function(){ 
        if($(this).find('.value').html() == locSplit[0]){
            $(".dropdownjs dd ul li").removeClass('selected');
            $(this).addClass('selected');
        } 
    })
    
    if($(".dropdownjs dd ul li.selected").length > 0){      
        if($().jquery.search(/1.3/) != -1){
            var firstText = $($(".dropdownjs dd ul li")[$(".dropdownjs dd ul li.selected").length-1]).children('a').html();
        }else{
            var firstText = $(".dropdownjs dd ul li.selected a").last().html();         
        }   
        $(".dropdownjs dt a span").html(firstText);
    }else{
        if($().jquery.search(/1.3/) != -1){
            var firstText = $($(".dropdownjs dd ul li")[0]).children('a').html();
        }else{
            var firstText = $(".dropdownjs dd ul li").first().children('a').html();
        }
        $(".dropdownjs dt a span").html(firstText);
    }
    
    $(".dropdownjs dt a").click(function() {
        $(".dropdownjs dd ul").toggle();
        return false;
    });
                
    $(".dropdownjs dd ul li a").click(function() {
        var text = $(this).html();
        $(".dropdownjs dt a span").html(text);
        $(".dropdownjs dd ul").hide();
        
        if($(this).children('.value').html() != ''){
            var newUrl = $(this).children('.value').html() + '.airpush.com';
        }else{
            var newUrl = 'airpush.com';
        }
        var oldUrl = location.href.replace(location.host,newUrl);
        location.href = oldUrl; 
        
        //alert();
        return false;        
    });
    
    
                
    function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
    }

    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
        if (! $clicked.parents().hasClass("dropdownjs"))
            $(".dropdownjs dd ul").hide();
    });
    
    
	$('.hover').each(function(a){
				switch(this.tagName){
					case 'A':
						$(this).attr('data-img-ori',$($(this).children()[0]).attr('src'));
						var hover = $($(this).children()[0]).attr('src').split('.')
						var hreplace = hover[0]+'-hover.'+hover[1]
						$(this).attr('data-img-hover',hreplace);
						$(this).unbind('hover').hover(function(e){							
							var hreplace = $(this).attr('data-img-hover');
							$($(this).children()[0]).attr('src',hreplace);
						},function(e){					
							var hreplace = $(this).attr('data-img-ori');
							$($(this).children()[0]).attr('src',hreplace)											
						});
					break;
					case 'DIV':
						$(this).attr('data-img-ori',$($(this).children()[0]).attr('src'));
						var hover = $($(this).children()[0]).attr('src').split('.')
						var hreplace = hover[0]+'-hover.'+hover[1]
						$(this).css('cursor','pointer');
						$(this).attr('data-img-hover',hreplace);
						$(this).unbind('hover').hover(function(e){							
							var hreplace = $(this).attr('data-img-hover');
							$($(this).children()[0]).attr('src',hreplace);
						},function(e){					
							var hreplace = $(this).attr('data-img-ori');
							$($(this).children()[0]).attr('src',hreplace)											
						});					
						$(this).click(function(){
							window.location = $(this).attr('data-href');
						})
					break;
					case 'BUTTON':
						$(this).attr('data-img-ori',$($(this).children()[0]).attr('src'));
						var hover = $($(this).children()[0]).attr('src').split('.')
						var hreplace = hover[0]+'-hover.'+hover[1]
						$(this).css('cursor','pointer');
						$(this).attr('data-img-hover',hreplace);
						$(this).unbind('hover').hover(function(e){							
							var hreplace = $(this).attr('data-img-hover');
							$($(this).children()[0]).attr('src',hreplace);
						},function(e){					
							var hreplace = $(this).attr('data-img-ori');
							$($(this).children()[0]).attr('src',hreplace)											
						});				
					break;
				}
			})


});

