// Function WriteSwf
function listCity(str)
{
	if (str==""){
	  document.getElementById("listCity1").innerHTML="";
	  return;
  	} 
	var params = 'pid=' + jQuery('#listCity').val();
	
	//activeLoginWait(true) 
	jQuery.ajax({ 
	      url:MOD_LIST_CITY_AJAX, 
	      type: "POST", 
	      data: params, 
	      async:false, 
	      success: function(msg){ 
	      	//doMemberLoginResult(msg); 
		   
			   jQuery('#listCity1').html(msg)
	      } 
	    }); 
}
jQuery(document).ready(function(){
	jQuery('#scrollbar1').tinyscrollbar( );
	jQuery('#scrollbar2').tinyscrollbar({ axis: 'y'});
	jQuery('#scrollbar3').tinyscrollbar({ axis: 'y'});
	jQuery('#scrollbar4').tinyscrollbar({ axis: 'y'});
});

function WriteSwf(img,wsize,hsize){
    document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+wsize+"\" height=\""+hsize+"\">");
    document.write("<param name=\"movie\" value=\""+img+"\">");
    document.write("<param name=\"quality\" value=\"high\">");
    document.write("<param name=wmode value=transparent>");
    document.write("<param name=\"menu\" value=\"false\">");
    document.write("<embed src=\""+img+"\" wmode=\"transparent\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+wsize+"\" height=\""+hsize+"\" menu=\"false\"></embed>");
    document.write("</object>");
}
// check email
function checkEmail(strEmail) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strEmail)){
        return (true)
    }
    return false;
}

function checksearch()
{
    if(jQuery("input#keyword").val() == '' || jQuery("input#keyword").val() == SEARCH_DEFAULT_TEXT)
    {
        alert("Chưa nhập giá trị vào ô tiềm kiếm!");
        jQuery("input#keyword").focus();
        return false;
    }
    return true;
}
function doSearch()
{
    if(!checksearch())
        return;
    jQuery('#submitSearch').val('OK');
    var pd = jQuery('#pd').val();
  jQuery('#searchForm').attr('action', MOD_PRODUCT.substr(0, MOD_PRODUCT.length - 5)+'/'+ pd + '/' + MOD_SEARCH + '.html');
    jQuery('#searchForm').submit();
}

function getYoutubeVideoCode(w, h, path_video, divId){
	path_video = path_video.replace('watch?v=', 'embed/');
	var sHtml = '<iframe title="YouTube video player" width="' + w + '" height="' + h + '" src="' + path_video + '" frameborder="0" allowfullscreen></iframe>';
	jQuery('#' + divId).html(sHtml);
}

function getOrginalVideoCode(w, h, path_video, divId, path_image){
    // cap nhat doan video
    var s1 = new SWFObject(jsPathPrefix + "gui/frontend/player/player.swf","ply", w, h, "9");
    s1.addParam("allowfullscreen","true");
    s1.addParam("wmode","transparent");
    s1.addParam("allowscriptaccess","always");
    s1.addVariable('controlbar','over');
    s1.addParam('flashvars','file=' + jsPathPrefix + path_video + '&image=' + jsPathPrefix + path_image);
    s1.addVariable('autostart','false');
    s1.write(divId);
}

jQuery(document).ready(function(){
	
jQuery("ul.subnav ").parent().append("<span><img src='"+jsPathPrefix+"gui/frontend/templates/default/images/button.gif'/></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	jQuery("ul.listProductCategory  li span").click(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		jQuery(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		jQuery(this).parent().hover(function() {
		}, function(){	
			jQuery(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			jQuery(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			jQuery(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

	// Ngan chan mo file van ban tren trang hien tai
	jQuery('a').click(function(){
	    if(this.href.indexOf('.doc') > -1 || this.href.indexOf('.xls') > -1 || this.href.indexOf('.pdf') > -1){
	        window.open(this.href);
	        return false;
	    }
	});
	//
	// isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	//
	emptyHtml = '<img src="' + jsPathPrefix + 'gui/frontend/templates/default/images/trans.gif" width="1" height="1" alt = "" />';
	jQuery("td:empty").html(emptyHtml);
	//jQuery("div:empty").html(emptyHtml);
	//jQuery("span:empty").html(emptyHtml);
	jQuery('.slideLine img').pngfix();
    // Hiển thị menu nào đang được chọn
    var url = self.location.href;
    url = url.toLowerCase();
    var found = false;
    
	jQuery('#topMenu li').each(function(){
    	var id = jQuery(this).attr('id');
    	if(id != ''){
    		id = id.replace('mnu_', '');
    		id = id.toLowerCase();
    		if(url.indexOf('/' + id + '/') > -1 || url.indexOf('/' + id + '.html') > -1){
    			jQuery(this).addClass('current');
    			found = true;
    		}
    	}
    });
	if(!found){
		jQuery('#mnu_home').addClass('current');
	}
    
	//
	jQuery('a#btnSearch').click(function(){
		doSearch();
		return false;
	});
	jQuery('#kk').click(function(){
		alert("ngue");
		return false;
	});
	
	jQuery('input#keyword').focus(function() {
		if (jQuery(this).val() == SEARCH_DEFAULT_TEXT) {
			jQuery(this).val('');
		}
	});
	jQuery('input#keyword').blur(function() {
		if (jQuery(this).val() == '') {
			jQuery(this).val(SEARCH_DEFAULT_TEXT);
		}
	});
	jQuery('input#keyword').blur();
	jQuery('input#keyword').keypress(function(event) {
		if (event.keyCode == '13') {
			doSearch();
			return false;
		}
		return true;
	});
});
Cufon.replace('#cufon h2,#cufon h1,.contentIndentH , .li_scrollText a span, .newsTitle h2, .name h2, .listItemHeader h3, .listAgentTitle,.color_name,.postionLinkCategory  .menuHome a,ul.listProductCategory  li ul.subnav li');

//top menu
ddsmoothmenu.init({
	mainmenuid: "smoothmenu1", //menu DIV id
	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu', //class added to menu's outer DIV
	//customtheme: ["#1c5a80", "#18374a"],
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

//Carousel
var isAutoDoiTac = false;
var objScrollDoiTac = null;

function RunDoiTac(numScroll,numBreak,divIDScroll){			            	    
	isAutoDoiTac = false;
	
	if((numScroll * 1) < 1) return;
	
	var numberScroll = numScroll * 1;
	if (numberScroll > numBreak ) numberScroll = numBreak; 
	
	if((numScroll * 1) > numBreak){
		isAutoDoiTac = true;
	}
	jQuery(divIDScroll).jCarouselLite({	
		btnNext: "a#a_next",
		btnPrev: "a#a_prev",	                
		isAuto : isAutoDoiTac,
		vertical: false,
		auto: "3000" * 1 ,
		speed: "800" * 1 ,
		visible: numberScroll // display 4 images		            
	});        
				
	objScrollDoiTac = jQuery(divIDScroll); 
}
function stopScrollDoiTac(){
	if(isAutoDoiTac == false) return;
	objScrollDoiTac.scrollObj.isAuto = false;		        	
}

function scrollContinueDoiTac(){
	if(isAutoDoiTac == false) return;
	objScrollDoiTac.scrollObj.isAuto = true;
}
jQuery(document).ready(function(){
	//Larger thumbnail preview  
	jQuery("a.movers").hover(function() {
		jQuery(this).css({'z-index' : '10'});
		jQuery(this).find('img').addClass("hover").stop()
			.animate({
				marginTop: '-10px', 
				marginLeft: '0px',
				marginRight: '0px',
				marginBottom: '0px',
				top: '50%', 
				left: '50%', 
				width: '210px', 
				padding: '0px' 
			}, 200);
		
		} , function() {
		jQuery(this).css({'z-index' : '0'});
		jQuery(this).find('img').removeClass("hover").stop()
			.animate({
				marginTop: '0', 
				marginLeft: '0',
				marginRight: '0px',
				marginBottom: '0px',
				top: '0', 
				left: '0', 
				width: '200px', 
				padding: '0px'
			}, 900);
	});
	//slider
	jQuery(window).load(function() {
	    jQuery('#slider').nivoSlider({
	        effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
	        slices:17,
	        animSpeed:600,
	        pauseTime:5000,
	        startSlide:0, //Set starting Slide (0 index)
	        directionNav:false, //Next & Prev
	        directionNavHide:true, //Only show on hover
	        controlNav:false, //1,2,3...
	        controlNavThumbs:false, //Use thumbnails for Control Nav
	        controlNavThumbsFromRel:false, //Use image rel for thumbs
	        controlNavThumbsSearch: '.jpg', //Replace this with...
	        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
	        keyboardNav:true, //Use left & right arrows
	        pauseOnHover:false, //Stop animation while hovering
	        manualAdvance:false, //Force manual transitions
	        captionOpacity:0.8, //Universal caption opacity
	        beforeChange: function(){},
	        afterChange: function(){},
	        slideshowEnd: function(){} //Triggers after all slides have been shown
	    });
	});
});
/*search */
jQuery(document).ready(function() {

	//grab all the anchor tag with rel set to shareit
	jQuery('a[rel=shareit], #shareit-box').mouseenter(function() {		
		
		//get the height, top and calculate the left value for the sharebox
		var height = jQuery(this).height();
		var top = jQuery(this).offset().top;
		
		//get the left and find the center value
		var left = jQuery(this).offset().left + (jQuery(this).width() /2) - (jQuery('#shareit-box').width() / 2);		
		//grab the href value and explode the bar symbol to grab the url and title
		//the content should be in this format url|title
		var value = jQuery(this).attr('href').split('|');
		
		//assign the value to variables and encode it to url friendly
		var field = value[0];
		var url = encodeURIComponent(value[0]);
		var title = encodeURIComponent(value[1]);

		
		//display the box
		jQuery('#shareit-box').show();
		
		//set the position, the box should appear under the link and centered
		jQuery('#shareit-box').css({'top':top, 'left':left});

	});

	//onmouse out hide the shareit box
	jQuery('#shareit-box').mouseleave(function () {
		jQuery(this).hide();
	});

});

